28kids
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
the problem of the code is, even the customer is not eligible for the role discount, the price_html still return as ‘vip discount applied’
add_action("woocommerce_single_product_summary", function () { global $product; function getProtectedValue($obj, $name) { $array = (array)$obj; $prefix = chr(0).'*'.chr(0); return $array[$prefix.$name]; } $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 ""; } else{ foreach( $rules as $r ) { $check_role = $r->getRoleDiscounts(); foreach( $check_role as $c ) { if (in_array('vip', getProtectedValue($c,'roles'))) { echo 'vip discount applied'; break; } } } } });
thank you i did and it works fine, just wondering how to display it like
$100$80 *vip price*in single product page?
Viewing 3 replies - 1 through 3 (of 3 total)