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

时间:2018-02-22 10:48:18

标签: function woocommerce shipping

我有这个代码在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>'; } } }

1 个答案:

答案 0 :(得分:0)

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