我在我的WooCommercestore 里有一个免费的送货柜台.它通过以下代码实现:
// free shipping counter
add_action( 'woocommerce_before_cart', 'ml_free_shipping_cart_notice' );
function ml_free_shipping_cart_notice() {
$min_amount = 150; //change this to your free shipping threshold
$current = WC()->cart->subtotal;
if ( $current < $min_amount ) {
$added_text = 'Do darmowej przesyłki brakuje jeszcze ' . wc_price( $min_amount - $current ) . '!';
$return_to = wc_get_page_permalink( 'shop' );
$notice = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), 'Kontynuuj zakupy', $added_text );
wc_print_notice( $notice, 'notice' );
}
}
// ************************************************************************************
// free shipping info after 150pln
add_action( 'woocommerce_before_cart', 'free_shipping_info' );
function free_shipping_info() {
$min_amount = 150; //change this to your free shipping threshold
$current = WC()->cart->subtotal;
if ( $current >= $min_amount ) {
$added_text = 'Przekroczyłeś 150zł! Twoje zamówienie wyślemy za darmo! :) Wybierz dowolny sposób wysyłki!';
$return_to = wc_get_page_permalink( 'shop' );
$notice = sprintf( $added_text );
wc_print_notice( $notice, 'notice' );
}
}
第一部分在购物车页面上显示计数器-如果购物车数量低于150pln,它将显示客户需要花费多少钱才能获得免费送货.如果客户超过150pln,代码的第二部分表示现在免费送货.
But there is a problem if customer uses discount code. Example, like on the attached screen
- 购物车中的总金额=164,68pln,因此允许免费送货.
- 客户添加了15%的折扣代码,因此总数现在是139,98 PLN,在这种情况下,送货还不是免费的. 在这种情况下,柜台应该再次显示他需要花费多少(S)才能获得免费送货.
我想这是微不足道的简单,但不知道如何修改代码,以工作的预期.