3v4l.org

run code in 300+ PHP versions simultaneously
<?php * SEO - Product Custom Meta Description */ add_filter( 'aioseop_description', 'aioseop_mod_wc_desc', 10, 1 ); function aioseop_mod_wc_desc( $original_description ){ // Product title – sku – Product description. $sku = ''; $product_description = ''; $title = ''; global $post; if( 'product' !== $post->post_type || ! is_single() ){ return $original_description; } $title = $post->post_title; $sku = get_post_meta($post->ID, '_sku', true); $product_description = $post->post_content; $product_description = preg_replace( '/[\p{Z}\s]{2,}/u', ' ', $product_description); $meta_description = "$title - $sku - $product_description"; $aio = new All_in_One_SEO_Pack; $meta_description = $aio->trim_excerpt_without_filters( $meta_description ); return $meta_description; } /** * HOLIDAY VACATION MODE * * • Activate Holiday Vacation Mode snippet and change dates * • Put same instructions manually on contact us page by editing the page * • Activate sidebar widget 'Closed til' with closing info and change dates * • Do email auto response in domain cpanel under 'mail' * * General Text: * DogShoppe.net is Temporarily Closed from October 27 thru Nov 2, 2017 and Checkout has been disabled. At this time, you may create an account and add products to your Shopping Cart, which will be saved so that you may return and complete your order after Nov 2. Orders placed prior to Oct 27 will ship as per the time frame advised. All inquiries, emails and requests will be answered on or shortly after Nov 2. We sincerely apologize for the inconvenience and thank you for your patience. * * */ /** * @snippet Holiday - Vacation Mode WooCommerce Holiday/Pause Mode * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 * @sourcecode https://businessbloomer.com/?p=20862 * @author Rodolfo Melogli * @testedwith WooCommerce 2.6.4 * @original snpppet does not allow customers to add to cart Deb commented out first 2 lines which allow add to cart but not checkout */ // Trigger Holiday Mode add_action ('init', 'bbloomer_woocommerce_holiday_mode'); // Disable Cart, Checkout, Add Cart function bbloomer_woocommerce_holiday_mode() { // remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); // remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 ); remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 ); add_action( 'woocommerce_before_main_content', 'bbloomer_wc_shop_disabled', 5 ); add_action( 'woocommerce_before_cart', 'bbloomer_wc_shop_disabled', 5 ); add_action( 'woocommerce_before_checkout_form', 'bbloomer_wc_shop_disabled', 5 ); } // Show Holiday Notice function bbloomer_wc_shop_disabled() { wc_print_notice( 'DogShoppe.net is Temporarily Closed while we update our shopping cart and Checkout has been disabled. At this time, you may create an account and add products to your Shopping Cart, which will be saved so that you may return and complete your order after we re-open. Orders placed prior to Jan 5 will ship as per the time frame advised. All inquiries, emails and requests will be answered as quickly as possible. We sincerely apologize for the inconvenience and thank you for your patience.', 'error'); } /** * CATEGORY PAGE - Change shop columns to 4 */ //change shop columns to 4 wide from 3// add_filter( 'storefront_loop_columns', function() { return 4; } ); /** * CATEGORY PAGE - Allow HTML in Category Descriptions * * By default WordPress strips HTML from category descriptions. You can get around this by adding a small snippet to your theme functions.php file: * * The first part prevents html from being stripped from term descriptions. The second part prevents html being stripped out when using the term description function (http://codex.wordpress.org/Function_Reference/term_description).  https://docs.woocommerce.com/document/allow-html-in-term-category-tag-descriptions/ */ foreach ( array( 'pre_term_description' ) as $filter ) { remove_filter( $filter, 'wp_filter_kses' ); } foreach ( array( 'term_description' ) as $filter ) { remove_filter( $filter, 'wp_kses_data' ); } /** * CATEGORY PAGE - Hide Sub-Category Product Count * * https://docs.woocommerce.com/document/hide-sub-category-product-count-in-product-archives/ */ add_filter( 'woocommerce_subcategory_count_html', 'jk_hide_category_count' ); function jk_hide_category_count() { // No count } /** * CHECKOUT - Proceed to Paypal Text * * The original text on the checkout page was Proceed to Paypal - this code changes it to what you want under the translated text line */ /* Change the "Proceed to PayPal" button text in the WooCommerce checkout screen * Add this to your theme's functions.php file */ add_filter( 'gettext', 'custom_paypal_button_text', 20, 3 ); function custom_paypal_button_text( $translated_text, $text, $domain ) { switch ( $translated_text ) { case 'Proceed to PayPal' : $translated_text = __( 'Proceed to Checkout', 'woocommerce' ); break; } return $translated_text; } /** * FOOTER - Remove Original Copyright * * Remove original Copyright before widget area at bottom of page */ /* Remove original Copyright Line from Footer area */ add_action( 'init', 'custom_remove_footer_credit', 10 ); function custom_remove_footer_credit () { remove_action( 'storefront_footer', 'storefront_credit', 20 ); } /** * PRODUCT PAGE - Change Related Products Text * * The Related products below the product on the product page - changed the font under additional css to Lato. But it isn't correct Related products (products isn't capitalized)- changed to uppercase to agree with description tab on the same page. */ /** * Change text strings - Related products to * * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext */ function my_text_strings( $translated_text, $text, $domain ) { switch ( $translated_text ) { case 'Related products' : $translated_text = __( 'RELATED PRODUCTS >', 'woocommerce' ); break; } return $translated_text; } add_filter( 'gettext', 'my_text_strings', 20, 3 ); /** * CATEGORY PAGE - Remove Add To Cart Button * * REMOVE THE ADD TO CART BUTTON ON THE CATEGORY PAGE - IT LOOKED MESSY */ /* Remove add to cart button on Category pages */ function remove_loop_button(){ remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); } add_action('init','remove_loop_button'); /** * CATEGORY PAGE - Number of Products per Page */ // Display 100 Woocommerce products per page. add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 100;' ), 20 ); /** * Product CSV Importer - Menu Order - Add a custom column to the Product exporter * * Product CSV Importer - Menu Order - Add a custom column to the Product exporter and the exporter column menu. */ /* * Product CSV Importer - Menu Order - Add a custom column to the Product exporter and the exporter column menu. * * @param array $columns * @return array $columns */ function add_export_column( $columns ) { // column slug => column name $columns['menu_order'] = 'Menu Order'; return $columns; } add_filter( 'woocommerce_product_export_column_names', 'add_export_column' ); add_filter( 'woocommerce_product_export_product_default_columns', 'add_export_column' ); /** * Provide the data to be exported for one item in the column. * * @param mixed $value (default: '') * @param WC_Product $product * @return mixed $value - Should be in a format that can be output into a text file (string, numeric, etc). */ function add_export_data( $value, $product ) { $value = $product->get_meta( 'custom_column', true, 'edit' ); return $value; } // Filter you want to hook into will be: 'woocommerce_product_export_product_column_{$column_slug}'. add_filter( 'woocommerce_product_export_product_column_custom_column', 'add_export_data', 10, 2 ); /** * Product CSV Importer - Menu Order - Register a 'Custom Column' column * * Product CSV Importer - Menu Order - Register a 'Custom Column' column in the Product Importer. */ /** * Product CSV Importer - Menu Order - Register a 'Custom Column' column in the Product Importer. * * @param array $options * @return array $options */ function add_column_to_importer( $options ) { // column slug => column name $options['menu_order'] = 'Menu Order'; return $options; } add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_column_to_importer' ); /** * Add automatic mapping support for 'Custom Column'. * This will automatically select the correct mapping for columns named 'Custom Column' or 'custom column'. * * @param array $columns * @return array $columns */ function add_column_to_mapping_screen( $columns ) { // potential column name => column slug $columns['Menu Order'] = 'menu_order'; return $columns; } add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'add_column_to_mapping_screen' ); /** * Process the data read from the CSV file. * This just saves the value in meta data, but you can do anything you want here with the data. * * @param WC_Product $object - Product being imported or updated. * @param array $data - CSV data read for the product. * @return WC_Product $object */ function process_import( $object, $data ) { if ( ! empty( $data['custom_column'] ) ) { $object->update_meta_data( 'custom_column', $data['custom_column'] ); } return $object; } add_filter( 'woocommerce_product_import_pre_insert_product_object', 'process_import', 10, 2 ); /** * SEARCH - Sort Results by Title or Name * * Existing Search Results list products by order entered - this changes the Search Result page to list products alphabetically by Name or Title of Product * 2017-11-16 - deactivated as Relevanssi was causing a fatal error when searching for partial words */ // SEARCH RESULTS - sort by TITLE OR NAME add_action('pre_get_posts','sortby_title_query'); function sortby_title_query($query) { if ( isset($_REQUEST['s']) ) { $query->set('orderby', 'title'); $query->set('order', 'ASC'); } } /** * IMAGES - ALT TEXT FOR PRODUCT IMAGES - AUTOMATICALLY * * When uploading product images from an csv - external url – no image alt txt or title is allowed for. I contacted the woocommerce github developers and this is not possible even with custom column code for the import file. All alt text needs to be added manually always in the media library. This snippet puts alt text on all product images in the source on the product pages –basedon the product title - but this is not reflected in the media library. * However it changes the logo to the alt text of the first product on the page - I have asked for a solution here at Stackflow * https://stackoverflow.com/questions/46775225/woocommerce-product-image-alt-text-set-automatically */ add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2); function change_attachement_image_attributes( $attr, $attachment ){ // Get post parent $parent = get_post_field( 'post_parent', $attachment); // Get post type to check if it's product $type = get_post_field( 'post_type', $parent); if( $type != 'product' ){ return $attr; } /// Get title $title = get_post_field( 'post_title', $parent); $attr['alt'] = $title; $attr['title'] = $title; return $attr; } /** * SEARCH - Relevanssi - Search Sku in Variations */ add_filter('relevanssi_content_to_index', 'rlv_index_variation_skus', 10, 2); function rlv_index_variation_skus($content, $post) { if ($post->post_type == "product") { $args = array('post_parent' => $post->ID, 'post_type' => 'product_variation', 'posts_per_page' => -1); $variations = get_posts($args); if (!empty($variations)) { foreach ($variations as $variation) { $sku = get_post_meta($variation->ID, '_sku', true); $content .= " $sku"; } } } return $content; } /** * IMAGES - Auto Add Image Attributes from Image Filename upon Upload * * http://millionclues.com/wordpress-tips/automatically-add-image-caption-description-and-alt-text-from-image-title/ * this is the alternative to the plugin automatically add meta data to images which causes a fatal error in csv importer * Use this instead */ // Auto Add Image Attributes From Image Filename function abl_mc_auto_image_attributes( $post_ID ) { $attachment = get_post( $post_ID ); $attachment_title = $attachment->post_title; $attachment_title = str_replace( '-', ' ', $attachment_title ); // Hyphen Removal $attachment_title = str_replace( '_', ' ', $attachment_title ); // Underscore Removal $attachment_title = ucwords( $attachment_title ); // Capitalize First Word $uploaded_image = array(); $uploaded_image['ID'] = $post_ID; $uploaded_image['post_title'] = $attachment_title; // Image Title $uploaded_image['post_excerpt'] = $attachment_title; // Image Caption $uploaded_image['post_content'] = $attachment_title; // Image Description update_post_meta( $post_ID, '_wp_attachment_image_alt', $attachment_title ); // Image Alt Text wp_update_post( $uploaded_image ); } add_action( 'add_attachment', 'abl_mc_auto_image_attributes' ); /** * SEARCH - Relevanssi - Enable Search in Specific Category * * Enable Search in Specific Category - (for Dog Flags Page links) - Mikko Saari - Plugin Author * That’s exactly what I wanted to see and now I see what’s going on in here. The taxonomy restriction is not getting through at all: WooCommerce product visibility filter is overriding.  https://wordpress.org/support/topic/custom-search-result-link-restrict-to-woocommerce-catgeory/#post-9534538 * * &nbsp; */ /* Relevanssi Search - Enable Search in Specific Category * Add this to your theme's functions.php file */ add_filter('relevanssi_modify_wp_query', 'rlv_modify_query'); function rlv_modify_query($query) { if (isset($query->query_vars['product_cat'])) { $query->query_vars['tax_query'][] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $query->query_vars['product_cat'], 'include_children' => false, ); } return $query; } /** * EMAIL - ADD IMAGE TO ORDER EMAILS * * EMAILS - ADD IMAGE TO ORDER EMAILS * * Adds product images to the WooCommerce order emails table * * https://gist.github.com/bekarice/faecd9090776d9602b34 * */ // Edit order items table template defaults function sww_add_wc_order_email_images( $table, $order ) { ob_start(); $template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php'; wc_get_template( $template, array( 'order' => $order, 'items' => $order->get_items(), 'show_download_links' => $show_download_links, 'show_sku' => true, 'show_purchase_note' => $show_purchase_note, 'show_image' => true, 'image_size' => array( 75, 75 ) ) ); return ob_get_clean(); } add_filter( 'woocommerce_email_order_items_table', 'sww_add_wc_order_email_images', 10, 2 ); /** * EMAIL - ADD BCC * * * ADD BCC TO EMAILS - Function adds a BCC header to emails that match our array * * NEW ORDER: new_order - XX * * CANCELLED ORDER: cancelled_order - XX * * FAILED ORDER: failed_order - XX * * ORDER ON HOLD: customer_on_hold_order * * PROCESSING ORDER: customer_processing_order * * COMPLETED ORDER: customer_completed_order * * REFUNDED ORDER: customer_refunded_order * * CUSTOMER INVOICE: customer_invoice * * CUSTOMER NOTE: customer_note * * RESET PASSWORD: customer_reset_password - XX * * NEW ACCOUNT: customer_new_account - XX * * USE MULTIPLE BCC `first@email.com, second@email.com` * * TAKEN FROM https://jessepearson.net/2016/10/adding-bcc-emails-woocommerce/ * * @param string $headers The default headers being used * * @param string $object The email type/object that is being processed */ function add_bcc_to_certain_emails( $headers, $object ) { // email types/objects to add bcc to $add_bcc_to = array( 'customer_on_hold_order', // ORDER ON HOLD EMAIL 'customer_completed_order', // COMPLETED ORDER EMAIL 'customer_refunded_order', // REFUNDED ORDER EMAIL 'customer_invoice', // CUSTOMER INVOICE EMAIL 'customer_note', // CUSTOMER NOTE EMAIL 'customer_processing_order', // PROCESSING ORDER EMAIL ); // if our email object is in our array if ( in_array( $object, $add_bcc_to ) ) { // change our headers $headers = array( $headers, 'Bcc: orders@dogshoppe.net, dogshoppe.net2@yahoo.com' ."\r\n", ); } return $headers; } add_filter( 'woocommerce_email_headers', 'add_bcc_to_certain_emails', 10, 2 ); /** * EMAIL - HEADER FONT SIZE * * https://stackoverflow.com/questions/17577835/wordpress-woocommerce-email-order-or-invoice-email-how-to-edit-css-style */ /** Change WooCommerce Email Headers **/ add_filter( 'woocommerce_email_styles', 'mmr_woocommerce_email_styles' ); function mmr_woocommerce_email_styles( $css ) { $css .= "#header_wrapper h1 { font-size:26px; }"; $css .= "#header_wrapper h1 { font-family:Arial,sans-serif; }"; $css .= "#header_wrapper h1 { font-weight:400; }"; return $css; } /** * ORDER Print - Remove fields - Add Image - Order Number Larger * * TYCHE Woocommerce Print Invoice & Delivery Note by Tyche */ // Remove Fields from printing on order function example_removed_order_info_invoice( $fields ) { unset( $fields['invoice_date'] ); unset( $fields['billing_phone'] ); return $fields; } add_filter( 'wcdn_order_info_fields', 'example_removed_order_info_invoice' ); // Add Image To Order function example_product_image( $product ) { if( isset( $product->id ) && has_post_thumbnail( $product->id ) ) { echo get_the_post_thumbnail( $product->id, array( 80, 80 ) ); } } add_action( 'wcdn_order_item_before', 'example_product_image' ); // Order Number Larger add_filter( 'wcdn_order_info_content', 'change_order_number_style', 10, 2 ); function change_order_number_style( $field_content, $field ) { if ( __( 'Order Number', 'woocommerce-delivery-notes' ) == $field[ 'label' ] ) { $field_content = '<span style="font-size:22px;font-weight:bold;">' . $field_content . '</span>'; } return $field_content; } /** * SEO - Remove Nag Admin * * SEO - removes update nag in admin pages for All in One SEO */ add_action('admin_menu', 'aioseop_remove_update_notice'); function aioseop_remove_update_notice(){ global $aioseop_update_checker; remove_action('admin_notices', array($aioseop_update_checker, 'key_warning')); } /** * SEARCH - Change Relevanssi throttle to 350 * * Limits search results to 250 results per word searched. The default is 500. 2017-11-28 - Setting to 250 was not allowing all the black lab flag results to be retrieved. Was only showing 68 instead of 90. * Changed setting to 350 and it showed 90 results. */ remove_filter('relevanssi_query_filter', 'relevanssi_limit_filter'); add_filter('relevanssi_query_filter', 'tighter_relevanssi_limit_filter'); function tighter_relevanssi_limit_filter($query) { return $query . " ORDER BY tf DESC LIMIT 350"; } /** * SEARCH - Sort Results by Title or Name - TAKE 2 * * 2017-11-18 - this also give a fatal error TRY THIS CODE SNIPPET FROM https://www.relevanssi.com/user-manual/relevanssi_hits_filter/ */ add_filter('relevanssi_modify_wp_query', 'rlv_sort_by_title'); function rlv_sort_by_title($q) { $q->set('orderby', 'post_title'); $q->set('order', 'asc'); return $q; } /** * Speed up WooCommerce * * Try this snippet to make site faster * Dave Hilditch March 11, 2015 @ 8:35 pm * * https://www.affiliatewebdesigners.com/2015/01/14/setting-hhvm-wordpress/ * Hi – I went through quite a bit of working optimising the underlying SQL queries until I then discovered you can simply remove them – they’re not required at all as all they’re doing is counting products in each category – that happens EVERY page load and updates the database – very inefficient. * Anyway – to stop this abominable code from running and seriously speed up your large woocommerce sites, add this line to your functions.php file: * remove_action( ‘woocommerce_before_shop_loop’, ‘woocommerce_result_count’, 20 ); * */ remove_action( ‘woocommerce_before_shop_loop’, ‘woocommerce_result_count’, 20 ); /** * ORDER Status - Add Status: In Progress * * IMPORTANT! - IF YOU DELETE THIS SNIPPET - ANY ORDERS WITH THE IN PROGRESS STATUS WILL JUST DISAPPEAR * MAKE SURE YOU CHANGE ANY ORDER WITH THE STATUS TO SOMETHING ELSE PRIOR TO EVER DELETING THIS SNIPPET * * A combination of code - 2018-01-09: * 1 - The top part to add the status is from here: https://wordpress.stackexchange.com/questions/199289/how-to-create-a-custom-order-status-in-woocommerce * 2 - The bottom part to change the order is from here: https://rudrastyh.com/woocommerce/order-statuses.html * 3 - Adds icon to new custom order status: This is from the Woocommerce Font IconMoon - copy of this is in DogShoppe Files Folder on hard drive https://rawgit.com/woothemes/woocommerce-icons/master/demo.html * * * */ // 1 New order status AFTER woo 2.2 IN PROGRESS add_action( 'init', 'register_my_new_order_statuses' ); function register_my_new_order_statuses() { register_post_status( 'wc-in-progress', array( 'label' => _x( 'In Progress', 'Order status', 'woocommerce' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'In Progress <span class="count">(%s)</span>', 'In Progress<span class="count">(%s)</span>', 'woocommerce' ) ) ); } add_filter( 'wc_order_statuses', 'my_new_wc_order_statuses' ); // Register in wc_order_statuses. function my_new_wc_order_statuses( $order_statuses ) { $order_statuses['wc-in-progress'] = _x( 'In Progress', 'Order status', 'woocommerce' ); return $order_statuses; } /* * 2 CHANGE STATUSES ORDER IN DROPDOWN LIST * @param array $wc_statuses_arr Array of all order statuses on the website */ function change_statuses_order( $wc_statuses_arr ){ $new_statuses_arr = array( 'wc-processing' => $wc_statuses_arr['wc-processing'], // 1 'wc-in-progress' => $wc_statuses_arr['wc-in-progress'], // 2 'wc-completed' => $wc_statuses_arr['wc-completed'], // 3 'wc-cancelled' => $wc_statuses_arr['wc-cancelled'], // 4 'wc-refunded' => $wc_statuses_arr['wc-refunded'], // 5 'wc-failed' => $wc_statuses_arr['wc-failed'], // 6 'wc-pending' => $wc_statuses_arr['wc-pending'], // 7 'wc-on-hold' => $wc_statuses_arr['wc-on-hold'] // 8 ); return $new_statuses_arr; } add_filter( 'wc_order_statuses', 'change_statuses_order' ); /** * 3 ADD ORDER STATUS ICON CSS */ add_action('admin_head', 'in_progress_font_icon'); function in_progress_font_icon() { echo '<style> .widefat .column-order_status mark.in-progress:after{ font-family:WooCommerce; speak:none; font-weight:400; font-variant:normal; text-transform:none; line-height:1; -webkit-font-smoothing:antialiased; margin:0; text-indent:0; position:absolute; top:0; left:0; width:100%; height:100%; text-align:center; } .widefat .column-order_status mark.in-progress:after{ content:"\e020"; color:#CC0066; } </style>'; }
Output for 7.1.0 - 7.1.12, 7.2.0 - 7.2.1
Parse error: syntax error, unexpected '*', expecting end of file in /in/m0kdO on line 2
Process exited with code 255.

preferences:
172.73 ms | 1003 KiB | 7 Q