Check the active rules for the product
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
add_action("woocommerce_single_product_summary", function () { global $product; $calculateProduct = function ($product) { $rules = []; if ($product instanceof WC_Product_Variable) { foreach ( $product->get_available_variations("obj") as $variation ) { foreach (adp_functions()->getActiveRulesForProduct($variation, 1) as $rule) { $rules[$rule->getId()] = $rule; } } } elseif ($product instanceof WC_Product_Simple) { foreach (adp_functions()->getActiveRulesForProduct($product, 1) as $rule) { $rules[$rule->getId()] = $rule; } } return $rules; }; $rules = []; if ($product instanceof WC_Product_Grouped) { $children = array_filter( array_map( 'wc_get_product', $product->get_children() ), 'wc_products_array_filter_visible_grouped' ); foreach ($children as $childProduct) { $rules = $calculateProduct($childProduct); } } else { $rules = $calculateProduct($product); } if (count($rules) === 0) { echo "Your text"; } }); |