php - 可变产品的价格 (woocommerce)

标签 php wordpress woocommerce

请告诉我。篮子从哪里获得变分产品的值(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/

相关文章:

php - 检查 2 个数据库表的用户登录情况

javascript - php "detect"可以通过javascript重定向吗?

php - ffmpeg 捕获两种不同大小的图像

javascript - 将时间格式数据显示到highcharts中

php - 使用 AJAX 从 <select> 下拉列表中检索值?

php - 在 Woocommerce 单个产品页面上显示 dokan 供应商名称

json - Wordpress REST API 搜索产品

WordPress 在 "draft"操作中将 post_status 设置为 'save_post'

wordpress - htaccess 将domain2.com重定向到domain1.com/specific-page的 final方法

css - 为不同的网址显示不同的图像