tsibiski
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Here was my solution, for anyone else who comes along with the same question. I put this in my theme’s functions.php.
This is working well. It prevents discounts being applied to products under my specified price.
add_filter(
'pms_woo_get_discounted_price',
'my_disable_member_discount_under_500',
10,
5
);
function my_disable_member_discount_under_500(
$discounted_price,
$base_price,
$product_id,
$member_id,
$product
) {
if ( empty( $product ) || ! is_object( $product ) ) {
return $discounted_price;
}
/*
* Categories that should enforce
* the minimum-price membership rule
*/
$restricted_categories = array(
'my-category',
// 'another-category',
// 'another-category-2',
);
/*
* Check whether product belongs
* to one of the restricted categories
*/
$has_restricted_category = false;
foreach ( $restricted_categories as $category_slug ) {
if ( has_term( $category_slug, 'product_cat', $product_id ) ) {
$has_restricted_category = true;
break;
}
}
/*
* If product is NOT in a restricted category,
* allow normal discounts
*/
if ( ! $has_restricted_category ) {
return $discounted_price;
}
/*
* Apply minimum price rule
*/
$original_price = (float) $base_price;
if ( $original_price < 500 ) {
return null;
}
return $discounted_price;
}
Viewing 1 replies (of 1 total)