get price for certain variable products not possible
-
hello, i have a problem with a query. maybe someone has a solution. it’s about the following. i have created a custom field on user level with acf. here i can create a discount for a user which works globally on all products. we only offer different discount on customer level, no product has a product level sales price. my problem now is that for the product variants which have the same price the discount is not deducted in the product view, for all other simple and variable products (which have a different price per variant) it works flawlessly! in the shopping cart the price is then displayed correctly, so it is only about the product view. here is my code:
add_filter(‘woocommerce_product_get_sale_price’, ‘customergroup_price’, 10, 2 );
add_filter( ‘woocommerce_product_get_price’, ‘customergroup_price’, 10, 2 );
add_filter( ‘woocommerce_product_variation_get_price’, ‘customergroup_price’, 10, 2 );
add_filter( ‘woocommerce_product_variation_get_sale_price’, ‘customergroup_price’, 10, 2 );function customergroup_price( $price, $product ){
$user = wp_get_current_user();
$discount = get_field( ‘field_624af1556d9fc’ , $user);$regularPrice = $product->get_regular_price();
$salesprice = $price;if(!empty($discount)){
$salesprice = floatval($regularPrice) * (100 – $discount) / 100;
}return $salesprice;
}anyone have an idea what is wrong?
kindly
- The topic ‘get price for certain variable products not possible’ is closed to new replies.