Woocommerce购物车消息,如果需要运输

问题描述 投票:-1回答:1

我有这个代码在Woocommerce购物车和结帐页面上添加两行,但我只想显示是否需要发货。我怀疑$ needs_shipping可能需要在某处,但不知道在哪里。

add_action('woocommerce_cart_totals_before_order_total', 'promote_free_shipping');
add_action('woocommerce_review_order_after_shipping', 'promote_free_shipping');
function promote_free_shipping() {
if (WC()->cart->cart_contents_total) {
    $total = WC()->cart->get_displayed_subtotal();
                    echo '<tr class="promote_free_shipping"><td colspan="2" style="text-align:center;">We aim to dispatch your order within 2 working days.</td></tr>';

    // Tell them how much to add to the cart to get free shipping.
    $free_shipping_threshold = 50;
    if ($total < $free_shipping_threshold) {
            echo '<tr class="promote_free_shipping"><td colspan="2" style="text-align:center;">For free delivery add <strong>'.wc_price($free_shipping_threshold-$total).'</strong> to your cart (excluding tour tickets).</td></tr>'; } } }
function woocommerce shipping
1个回答
0
投票

更换第一个钩子,因此它特定于运输而不是购物车总数,所以而不是woocommerce_cart_totals_before_order_total使用woocommerce_cart_totals_after_shipping

© www.soinside.com 2019 - 2024. All rights reserved.