Title says it all.
Bellow code works as it should, for simple products. But I cannot figure out, why it has no influence on Variable products. I have been searching through the net for filter-hooks, and experimenting with a mix of different of bellow script. No luck so far.
add_filter( 'woocommerce_product_get_price', 'custom_price_for_category_role', 10, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'custom_price_for_category_role', 10, 2 );
function custom_price_for_category_role( $price, $product ) {
//Get all product categories for the current product
$terms = wp_get_post_terms( $product->get_id(), 'product_cat' );
foreach ( $terms as $term ) {
$categories[] = $term->slug;
}
if ( ! empty( $categories ) && in_array( 'b2b', $categories, true ) && current_user_can('b2b') ) {
$price = (($price * 1.25) / 3);
}
return $price;
}
Bonus question: What could be the reason that woocommerce_product_get_regular_price, has no effect.(also for simple products) I would like to have the code only apply to regular price, and ignore sales price.