【问题标题】:WooCommerce-Send Custom Selected Price in CartWooCommerce-在购物车中发送自定义选择的价格
【发布时间】:2016-07-25 16:07:38
【问题描述】:

大家好,我已经根据我的要求定制了woo-commerce单品页面,所以现在有两个价格,第一个价格是我选择的自定义价格,第二个价格是我从WooCommerce产品页面输入的(从wp输入-管理仪表板),现在第二个价格正在购物车中,但我想通过自定义价格我如何才能实现这一点,请建议我提前谢谢你。

Using ajax I am changing my custom price 
 Custom Price:
 <p class="prices" id="demo" style="margin-left:22%;"></p>

Default Price:
<p class="prices"  id="demo" style="margin-left:22%;"><?php  echo $product->get_price_html(); ?></p>

更新: 我正在使用此代码

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price'); 
function add_custom_price( $cart_object ) {


  $custom_price = 70; // This will be your custome price 
  foreach ( $cart_object->cart_contents as $key => $value ) {
      $value['data']->price = $custom_price;
  }

}

现在 70 是静态价格,而不是这个我想传递段落,因为我正在使用 ajax 获得段落中的价格..

  <p class="prices" id="demo" style="margin-left:22%;"></p>

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:
    add_action('woocommerce_get_price','change_price_custom', 10, 2);
    function change_price_custom($price, $productd){
        return $price*2; // do calculation here
    }
    

    在主题的function.php中试试这个

    【讨论】:

    • 您的函数正在计算默认价格我想在购物车中传递自定义价格我正在使用 ajax 通过 ajax 进行计算我正在调用 php 文件,因为我已经编写了查询我该怎么做请建议。 ..
    • 请检查我在段落中更新的代码我得到了我的价格现在我想通过段落但它不起作用帮助我..
    • add_filter('woocommerce_get_price_html', 'my_price_html', 100, 2); function my_price_html( $price, $product ){ return '
      ur Price
      '; } // 挂钩获取价格 html
    猜你喜欢
    • 2015-11-28
    • 2019-12-21
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 2015-12-10
    • 2019-06-01
    相关资源
    最近更新 更多