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

pcww981p  于 2023-01-12  发布在  WordPress
关注(0)|答案(1)|浏览(112)

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

v8wbuo2f1#

更换了第一个挂钩,使其特定于运输而非推车总数,因此使用woocommerce_cart_totals_before_order_total而非woocommerce_cart_totals_after_shipping

相关问题