在 WooCommerce 中,我想知道是否有一個簡單的解決方案可以從總數中減去小計而不增加額外費用?這也出現在結帳、訂單(我的帳戶)和電子郵件通知等中。
這樣做的原因是我在產品中添加了定制費/附加費,即小計的10%的預訂費,我只想先支付附加費,然后離線(如收集)。
例如
- 小計 = 購買價格 = 100 英鎊
- 預訂費 = 10 英鎊
- 管理費 Ontop = 5 英鎊
- 現在支付總額 = 15 英鎊
那么,是否有一種簡單的方法可以從總計中洗掉小計,而無需在購物車總計中添加另一行?
這是我嘗試過的,但不幸的是無處可去,也不清楚如何做到這一點。
add_filter( 'woocommerce_calculated_total', 'custom_cart_total', 20, 2 );
function custom_cart_total( $total, $cart ) {
return $total - $subtotal;
}
和
add_action( 'woocommerce_calculate_totals', 'custom_calculate_total', 10, 1 );
function custom_calculate_total ($total, $cart) {
$total = WC()->cart->get_total;
$subtotal = WC()->cart->subtotal();
$sum_total = $total - $subtotal;
$woocommerce->cart->set_total($sum_total);
return $sum_total;
}
uj5u.com熱心網友回復:
該woocommerce_calculated_total過濾器鉤的確可以使用,只是$subtotal在當前的代碼是不明確的。
所以你得到:
// Allow plugins to filter the grand total, and sum the cart totals in case of modifications.
function filter_woocommerce_calculated_total( $total, $cart ) {
// Get subtotal
$subtotal = $cart->get_subtotal();
return $total - $subtotal;
}
add_filter( 'woocommerce_calculated_total', 'filter_woocommerce_calculated_total', 10, 2 );
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/402830.html
標籤:
