2

我目前正在与 WooCommerce 合作。以下函数与“woocommerce_before_calculate_totals”挂钩并更改产品的价值。这适用于简单的产品,但这不适用于变化:

add_action( 'woocommerce_before_calculate_totals', 'wwp_variable_add_cart_price' );
function wwp_variable_add_cart_price( $cart_object ) {
$current_user = new WP_User(wp_get_current_user()->id);
$user_roles = $current_user->roles;
foreach ($user_roles as $roles) {
    if ($roles == 'administrator'){
        foreach ( $cart_object->cart_contents as $key => $value ) {
            $wholesale = get_post_meta( $value['product_id'], '_wholesale_price', true );
            if ($wholesale){    
            $value['data']->price = $wholesale;
            }
}}}}

我需要为变化做一些不同的事情吗?或者上面应该工作吗?

4

1 回答 1

1

我设法通过添加以下代码行来解决这个问题:

$wholesalev = get_post_meta( $value['data']->variation_id, '_wholesale_price', true );
于 2013-08-05T08:14:14.143 回答