我有一个添加增值税的条件。如果条件为真,那么我需要更新增值税值 (0)。我的代码运行良好。但是它需要重新加载页面才能知道更新的增值税的价值。如何在不重新加载页面的情况下执行此操作?我的代码如下:
add_action( 'woocommerce_checkout_update_order_review', 'cm_checkout_based_on_amount' );
function cm_checkout_based_on_amount( $post_data ) {
WC()->customer->set_is_vat_exempt( false );
parse_str( $post_data, $output );
$minimum = 160;
$county = array('GB');
$cart_tot_order = WC()->cart->total;
if ( $cart_tot_order > $minimum && in_array( WC()->customer->get_shipping_country(), $county ) ){
WC()->customer->set_is_vat_exempt( true );
}
}
任何帮助将不胜感激。谢谢。
答案 0 :(得分:0)
您可以在这些详细信息更新后使用 jQuery 触发结帐/购物车更新,也可以发送带有订单评论片段的自定义数据。
要更新购物车/结帐触发这些:
// For checkout
$(document.body).trigger('update_checkout', { update_shipping_method: false });
// For cart
$(document.body).trigger('wc_update_cart');
发送自定义片段
add_filter('woocommerce_update_order_review_fragments', 'custom_wc_fragments');
function custom_wc_fragments($fragments)
{
ob_start();
echo 'Updated content here';
$updated_content = ob_get_clean();
$selector_of_the_element_you_want_to_update = '#order_review';
$fragments[$selector_of_the_element_you_want_to_update] = $updated_content;
return $fragments;
}
注意:这些代码无法立即使用,但它们是您处理此问题的一个开始。