简体   繁体   中英

WooCommerce - Hide shipping address when local pickup is chosen on thankyou page

I am using WordPress with WooCommerce plugin Last version on an e-commerce website.

I would like to hide the "Shipping Address" in WooCommerce "Order received" page when "Local Pickup" shipping method is chosen.

How can I achieve this?

Here is the screenshot Of the Order Received page:

在此输入图像描述

Thanks in advance

Yes it's possible overriding WooCommerce templates (copying the WooCommerce plugin templates folder to your active child theme or theme, renaming it woocommerce) .

You can use the same code as the answer of your previous question , but in an other template:
order/order-details-customer.php that is loaded on Thankyou WooCommerce page ("Order receive" page).

Replace in the portion of code from line 64 to the end on order/order-details-customer.php template with this code:

<?php
    // BEGIN HERE
    $shipping_local_pickup = false;
    if ( $items_totals = $order->get_order_item_totals() ) {
        foreach ( $items_totals as $items_total ) {
            if ( $items_total['value'] == 'Local Pickup' && !$shipping_local_pickup ) $shipping_local_pickup = true;
        }
    }
    // END

    if ( ! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && !$shipping_local_pickup ) : // HERE TOO ?>

    </div><!-- /.col-1 -->
    <div class="col-2">
        <header class="title">
            <h3><?php _e( 'Shipping Address', 'woocommerce' ); ?></h3>
        </header>
        <address>
            <?php echo ( $address = $order->get_formatted_shipping_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
        </address>
    </div><!-- /.col-2 -->
</div><!-- /.col2-set -->

<?php endif; ?>

This is tested and fully functional code

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM