Apply automatically a coupon based on specific cart items count in Woocommerce
I am trying to automatically trigger a coupon to be applied in the cart specifically for when there are 4 items in the cart. The coupon is pre-created in the Woocommerce back-end of the site "tasterbox" I am using an amended version from this answer code: Add WooCommerce coupon code automatically based on product categories Here is my code version: add_action( 'woocommerce_before_calculate_totals', 'wc_auto_add_coupons', 10, 1 ); function wc_auto_add_coupons( $cart_object ) { // Coupon code $coupon = 'tasterbox'; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Initialising variables