//APPLY COUPON AUTOMATICALLY IF PRODUCT ID IS IN THE CART add_action( 'woocommerce_before_cart', 'wpninja_apply_matched_coupons' ); function wpninja_apply_matched_coupons() { $coupon_code = 'sapikupon'; if ( WC()->cart->has_discount( $coupon_code ) ) return; foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { // this is your product ID $autocoupon = array( 1035 ); if( in_array( $cart_item['product_id'], $autocoupon ) ) { WC()->cart->add_discount( $coupon_code ); wc_print_notices(); } } }