Добавьте следующий фрагмент кода в файл functions.php вашей активной темы, чтобы выполнить вышеперечисленное -
function apply_discount_in_woocommerce_cart() {
$coupon_code = 'abc';
if ( WC()->cart->has_discount( $coupon_code ) ) return;
$specific_products = array( 12, 13, 14 ); // Assume 3 products ids
$all_products_count = 0;
foreach ( $specific_products as $product_id ) {
$product_cart_id = WC()->cart->generate_cart_id( $product_id );
$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );
if ( $in_cart ) {
$all_products_count++;
}
}
// check all products count equals to 3 on not
if( $all_products_count === 3 ) {
WC()->cart->add_discount( $coupon_code );
wc_print_notices();
}
}
add_action( 'woocommerce_before_cart', 'apply_discount_in_woocommerce_cart', 99 );
И не забудьте заменить фиктивные идентификаторы продуктов в массиве на идентификаторы ваших конкретных продуктов и код купона.