OHSM OHSM - 2 months ago 35x
PHP Question

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:

enter image description here

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:

    $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>
            <?php echo ( $address = $order->get_formatted_shipping_address() ) ? $address : __( 'N/A', 'woocommerce' ); ?>
    </div><!-- /.col-2 -->
</div><!-- /.col2-set -->

<?php endif; ?>

This is tested and fully functional code