Add JavaScript to all WooCommerce Products

If you need to do this on the single product page use this condition then enqueue the JavaScript files. function enqueue_single_product_javascript() { if(is_product()) { // Use wp_enqueue_script() } } add_action(‘wp_enqueue_scripts’, ‘enqueue_single_product_javascript’); https://developer.wordpress.org/reference/functions/wp_enqueue_script/ https://docs.woocommerce.com/document/conditional-tags/

Include WooCommerce product to all child categories

(1) Paste below code to your functions.php file function my_enqueue() { wp_enqueue_script( ‘my_custom_script’, get_template_directory_uri() . ‘/js/myscript.js’ ); } add_action( ‘admin_enqueue_scripts’, ‘my_enqueue’ ); (2) Create myscript.js file and paste below code in it and place the file in ‘yourtheme/js/’ folder. jQuery(document).ready(function () { jQuery(‘#categorychecklist’).prepend(‘<input type=”checkbox” id=”selectall”><label for=”selectall”>Select all subcategories.</label><hr>’); jQuery(‘#categorychecklist [type=”checkbox”]:not(#selectall)’).on(‘change’, function () { if(jQuery(‘#selectall’).is(‘:checked’)) { … Read more

(Woocommerce) Order by price when entering specific category

You can use the filter below, as suggested by @sabarnix at https://stackoverflow.com/questions/24939337/woocommerce-different-default-sorting-for-different-categories add_filter(‘woocommerce_get_catalog_ordering_args’, ‘tk_woocommerce_catalog_orderby’); function tk_woocommerce_catalog_orderby( $args ) { if( is_product_category( ‘shirts’ ) ) { $args[‘orderby’] = ‘meta_value_num’; $args[‘order’] = ‘ASC’; $args[‘meta_key’] = ‘_price’; } return $args; }

Custom email template for a specific product category

Firstly extend WC_Email class to define the email header, subject, email template for content secondly, add custom email class to the default WooCommerce email classes using woocommerce_email_classes filter, with trigger that calls terms if ( has_term( ‘Your Cat’, ‘product_cat’, $item[‘product_id’] ) ) lastly, Create an email template to be used to generate email content for … Read more