On our website we've got the function, which is displayed bellow, to change prices depending on user role. The problem is that if a customer logs in and has the premium role the prices will stay the same as if the customer isn't in that role. Is there a way to recalculate the cart prices?

add_filter('woocommerce_get_price', 'return_custom_price', $product, 2);
add_filter('woocommerce_product_variation_get_price', 'return_custom_price', $product, 2);

function return_custom_price($price, $product) {    
    if (! current_user_can('premium') || ! is_user_logged_in()) {
        global $post, $woocommerce;
        return $new_price = $price * 1.25;   
    return $price;
  • Hook available for that name is something before calculating total Jun 28 '19 at 18:26

Maybe you need to add :


I did something like this in opther project and thats worked:

 if (is_user_logged_in()) {
add_filter('woocommerce_product_variation_get_regular_price', 'my_custom_price', 10, 2);
add_filter('woocommerce_product_variation_get_price','my_custom_price', 10, 2); } function my_custom_price( $price ) {
global $post;

// Delete product cached price  (if needed)

// Return the new price

return $price = ($price * 1.1) ;}

Not the answer you're looking for? Browse other questions tagged or ask your own question.