Conditional product prices cart issue in WooCommerce 3

不问归期 提交于 2019-12-02 02:18:47

With your code you are just changing the displayed variation price range. So you will need a bit more for this:

// Simple, grouped and external products
add_filter('woocommerce_product_get_price', 'custom_price', 90, 2 );
add_filter('woocommerce_product_get_regular_price', 'custom_price', 90, 2 );

// Product variations (of a variable product)
add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'custom_price', 90, 2 );

// Variable product price ramge
add_filter('woocommerce_variation_prices_price', 'custom_variation_price', 90, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'custom_variation_price', 90, 3 );

function custom_price( $price, $product ) {
    // Only logged in users
    if ( ! is_user_logged_in() ) return $price; 

    // HERE the defined plan ID
    $plan_id = 1628;

    if ( wc_memberships_is_user_member( get_current_user_id(), $plan_id )  ) {
        $price *= 2; // set price x 2
    }
    return $price;
}

function custom_variation_price( $price, $variation, $product ) {
    // Only logged in users
    if ( ! is_user_logged_in() ) return $price; 

    // HERE the defined plan ID
    $plan_id = 1628;

    if ( wc_memberships_is_user_member( get_current_user_id(), $plan_id )  ) {
        $price *= 2; // set price x 2
    }
    return $price;
}

Code goes in function.php file of the active child theme (or active theme).

Tested and works on woocommerce 3+

Now custom prices in cart will be also reflected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!