Untitled
unknown
plain_text
2 years ago
877 B
21
Indexable
add_filter('b2bking_applicable_rules_products', 'b2bking_discount_rules_sale_price', 10, 5);
function b2bking_discount_rules_sale_price($results, $rule_type, $product_id, $user_id, $categories_array){
$rules = $results[0];
if ($rule_type == 'discount_everywhere'){
// calculate discount percentage of rule
$regular_price = get_post_meta($product_id,'_regular_price', true);
$sale_price = get_post_meta($product_id,'_sale_price', true);
if (!empty($sale_price)){
foreach ($rules as $index => $rule_id){
$howmuch = floatval(get_post_meta($rule_id, 'b2bking_rule_howmuch', true));
$discounted_rule_price = $regular_price * (100-$howmuch)/100;
if ($discounted_rule_price > $sale_price){
unset($rules[$index]);
}
}
}
}
return array($rules, $results[1]);
}Editor is loading...
Leave a Comment