A fast and reliable way to change WooCommerce behaviours
While working on WooCommerce websites, I’ve found that I was using (most of the times) 4 simple functions that allowed me to have a superior control on the created e-commerce solution.
In this post you’ll find functions for:
- Add WooCommerce CSS classes to any template you want
- Change WooCommerce products per page and product columns on listings
- Add BCC to all emails sent by WooCommerce
- Remove WooCommerce hooked actions and create your own function with it
Add WooCommerce CSS classes to a page template or a single template from custom post type
add_filter('body_class','add_this_classes'); function add_this_classes($classes) { //if is single from CPT "post_type" or page template "template.php" if(is_singular('post_type') || is_page_template('template.php')){ // add 'class-name' to the $classes array $classes[] = 'woocommerce'; $classes[] = 'woocommerce-page'; } // return the $classes array return $classes; }
Change WooCommerce products per page and columns
//Change products per page to 20 add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 20;' ), 20 ); add_filter('loop_shop_columns', 'loop_columns'); if (!function_exists('loop_columns')) { function loop_columns() { return 8; //change to 8 columns } }
Add BCC in all emails sent by WooCommerce
add_filter( 'woocommerce_email_headers', 'add_bcc_all_emails', 10, 2); function add_bcc_all_emails($headers, $object) { $headers = array(); $headers[] = 'Bcc: Name <[email protected]>'; $headers[] = 'Content-Type: text/html'; return $headers; }
Remove WooCommerce hooked action and use the function from it
//Remove add to cart from single product summary remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); woocommerce_template_single_add_to_cart();
7 replies on “4 Useful WooCommerce Functions”
Where do I have to put the bcc function?
It should be placed in your template’s functions.php file. You can reach it in this way: Appearance > Editor > click on functions.php on the right side of the page.
Would you happen to know how to add “reply-to” in the new order email?
For example, the new order email is sent from the admin email account. But I want to add “reply-to” to the customer so that I can reply directly from the email.
you can use the same function adding the reply-to parameter, like: $headers[] = “Reply-To: Recipient Name“;
you can use the same function adding the reply-to parameter, like: $headers[] = “Reply-To: Recipient Name “;
regarding bcc snippet – is there a way to only send confirmed orders to an email account.
@rfvcorreia:disqus, bbc snippet send in all woocommerce emails. How to send only when email to admin or by order status slug ?