我正在开发一个插件,它与WooCommerce工作,需要更新自定义价格后,提交订单在结帐页面。
问题:有可能吗?
我试过:
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');谢谢。
发布于 2016-09-07 14:44:53
您必须在另一个钩子中执行此操作,在计算完总计后将覆盖一个钩子,您必须在woocommerce_before_calculate_totals钩子中执行,因此将add_action调用更改为:
add_action( 'woocommerce_before_calculate_totals', 'action_woocommerce_review_order_after_submit' );
https://stackoverflow.com/questions/39370284
复制相似问题