我目前发现以下代码,显示了启用免费送货前的可用支出金额。我需要扩展逻辑,以使其仅显示国家/地区代码为GB,并且装运类别(弹头)是否等于包裹力量和/或小包裹。我需要添加什么?
function my_custom_wc_free_shipping_notice() {
if ( ! is_cart() && ! is_checkout() ) { // Remove partial if you don't want to show it on cart/checkout
return;
}
$packages = WC()->cart->get_shipping_packages();
$package = reset( $packages );
$zone = wc_get_shipping_zone( $package );
$cart_total = WC()->cart->get_displayed_subtotal();
if ( WC()->cart->display_prices_including_tax() ) {
$cart_total = round( $cart_total - ( WC()->cart->get_discount_total() + WC()->cart->get_discount_tax() ), wc_get_price_decimals() );
} else {
$cart_total = round( $cart_total - WC()->cart->get_discount_total(), wc_get_price_decimals() );
}
foreach ( $zone->get_shipping_methods( true ) as $k => $method ) {
$min_amount = $method->get_option( 'min_amount' );
if ( $method->id == 'free_shipping' && ! empty( $min_amount ) && $cart_total < $min_amount ) {
$remaining = $min_amount - $cart_total;
wc_add_notice( sprintf( 'Add %s more to get free shipping!', wc_price( $remaining ) ) );
}
}
}
add_action( 'wp', 'my_custom_wc_free_shipping_notice' );