请告诉我。篮子从哪里获得变分产品的值(value),随后乘以数字并发布总计和小计?问题是您需要将产品的成本从自定义字段发送到购物篮。
对于一个简单的产品来说,一切都已实现。以下函数已添加到文件 abstract-wc-product.php 中:
public function get_rrp_price( $context = 'view' ) {
return $this->get_meta( $key = 'rrp_price', $context = 'view' );
}
其中rrp_price - 是具有新价格的任意字段的名称。然后在模板 class-wc-cart.php 中,即以下函数中:
public function calculate_totals(
public function get_product_subtotal(
我已将 $product->get_price() 替换为 $product->get_rrp_price(),对于一个简单的产品来说,一切都有效!
但是当您添加可变产品时,购物篮会出现零。我不明白在什么地方可以修复它,我猜是在 class-wc-product-variable.php 中,但如果是这样,在哪里以及如何修复?
最佳答案
我以前遇到过这个问题,但我找到了解决方案,请检查下面的代码,我认为从中您可以得到完美的想法。
function opal_varient_price( $price, $variation ) {
if ( $variation->product_type == 'variation' ) {
$user = $user ? new WP_User( $user ) : wp_get_current_user();
$role = $user->roles[0];
if($role == 'detailer'){$pricex = get_post_meta( $variation->variation_id, 'dist',true);}
else if($role == 'reseller'){$pricex = get_post_meta( $variation->variation_id, 'res',true);}
else{ $pricex = $price;}
}
return $pricex;
}
add_filter( 'woocommerce_product_variation_get_regular_price', 'opal_varient_price' , 99, 2 );
add_filter( 'woocommerce_product_variation_get_sale_price', 'opal_varient_price' , 99, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'opal_varient_price', 99, 2 );
关于php - 可变产品的价格 (woocommerce),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46887026/