首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更新定制价格woocommerce

更新定制价格woocommerce
EN

Stack Overflow用户
提问于 2016-09-07 12:43:22
回答 1查看 493关注 0票数 1

我正在开发一个插件,它与WooCommerce工作,需要更新自定义价格后,提交订单在结帐页面。

问题:有可能吗?

我试过:

代码语言:javascript
复制
header('Location: http://myweb.com/?add-to-cart=477');

// define the woocommerce_review_order_after_submit callback 
function action_woocommerce_review_order_after_submit(  ) { 

    $custom_price = 10; // This will be your custome price  
    $target_product_id = 477;
    foreach ( $cart_object->cart_contents as $value ) {
        if ( $value['product_id'] == $target_product_id ) {
            $value['data']->price = $custom_price;
        }
    }
}
     
// add the action 
add_action( 'woocommerce_review_order_after_submit',     
'action_woocommerce_review_order_after_submit');

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-09-07 14:44:53

您必须在另一个钩子中执行此操作,在计算完总计后将覆盖一个钩子,您必须在woocommerce_before_calculate_totals钩子中执行,因此将add_action调用更改为:

add_action( 'woocommerce_before_calculate_totals', 'action_woocommerce_review_order_after_submit' );

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39370284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档