• Resolved cashismatt

    (@cashismatt)


    Hi everyone,

    I’m building an ecommerce site. I have products that can’t be delivered because of its dimensions (it’s an hardware store). So, I’d like to mark products as “only local pickup” and at the checkout I have to show only that one possibility and no others shipping options.

    Do you have an idea on how to do it??

    Thanks a lot for the support,

    Matteo

Viewing 7 replies - 1 through 7 (of 7 total)
  • Have you read thru the docs yet?

    WC Docs

    Try there first.

    Thread Starter cashismatt

    (@cashismatt)

    Yes, of course I have read it but what I desire is to hide other shipping options apart of “local pickup” if in the cart there is at least one product that requires that.

    That’s nice. It’s always a good read.

    You can try this hook.

    add_action( 'woocommerce_after_checkout_form', 'my_disable_shipping_local_pickup' );
     
    function my_disable_shipping_local_pickup( $available_gateways ) {
    global $woocommerce;
     
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping_no_ajax = $chosen_methods[0];
    if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {
     
    ?>
    <script type="text/javascript">
     
        jQuery('#customer_details .col-2').fadeOut();
     
    </script>
    <?php
         
    } 
     
    ?>
    <script type="text/javascript">
                jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
        var val = jQuery( this ).val();
        if (val.match("^local_pickup")) {
                    jQuery('#customer_details .col-2').fadeOut();
            } else {
            jQuery('#customer_details .col-2').fadeIn();
        }
    });
     
    </script>
    <?php
     
    }

    And then hide Ship To Different Address

    .woocommerce-shipping-fields{
    	display:none;
    }
    Thread Starter cashismatt

    (@cashismatt)

    I want to do it automatically when in the cart there is a “only local pickup” products.

    Anyway it seems doesn’t work. ‘local_pickup’ is the default name or do I have to put the slug I put in the shipping options??

    I don’t know what you mean by automatically. But I tested before I posted and it works for me. User goes and adds to cart user then goes to cart page, reviews and then goes to checkout page fills out billing and completes their order.

    If you’re not a coder you need to find someone that can help you customize this option to your needs.

    Thread Starter cashismatt

    (@cashismatt)

    How did you check if in the cart there are products that can’t be delivered?

    That script will hide it. Turn off calculator for shipping too

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Restrict shipping to ONLY LOCAL-PICKUP’ is closed to new replies.