[英]How to update total payable amount on checkout page woocommerce
我想將運費用於特定用戶角色,而不是所有用戶。 我嘗試使用woocommerce基於角色的運輸插件,但它在我的主題方面造成了問題。 因此,我決定使用woocommerce掛鈎執行此操作。 具有批發角色的用戶無需支付運費。
這是我的代碼
$excluded_role = "wholesale";
$user = wp_get_current_user();
if ( empty( $user ) ) return false;
if( in_array( $excluded_role, (array) $user->roles ))
{
global $woocommerce;
//echo $woocommerce->cart->get_cart_total();
?>
<script type="text/javascript">
jQuery(document).ready(function()
{
jQuery(".woocommerce-Price-amount.amount").html('<span class="woocommerce-Price-currencySymbol"><?php echo get_woocommerce_currency_symbol();?></span><?php echo $woocommerce->cart->get_cart_total();?>');
});
</script>
<?php
//return $woocommerce->cart->get_cart_total();
}
現在的問題是,當我單擊下訂單按鈕並且我沒有找到更新總應付金額的php方法時,此代碼未更新金額。
誰能建議我如何在結帳頁面上更新應付款總額。
提前致謝。
我將此代碼添加到了主題的function.php文件中。
function disable_shipping_calc_on_cart( $show_shipping ) {
$excluded_role = "wholesale";
$user = wp_get_current_user();
if ( empty( $user ) ) return false;
if( in_array( $excluded_role, (array) $user->roles ))
{
return false;
}
return $show_shipping;
}
add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'disable_shipping_calc_on_cart', 99 );
我工作.. :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.