2013-08-04 167 views
2

我目前正在使用WooCommerce。以下函數將鉤入「woocommerce_before_calculate_totals」並更改產品的值。這與簡單的產品工作正常,但這並不適用於變化:WooCommerce覆蓋購物車的價格

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; 
      } 
}}}} 

我需要做一些不同的變化?還是應該上面的工作?

回答

1

我管理通過添加以下代碼行,以解決這個問題:

$wholesalev = get_post_meta($value['data']->variation_id, '_wholesale_price', true); 
相關問題