0

I'm new with shortcodes and programming... I would like to know how to display the store location in a multi vendor site with Dokan plugin when local pickup is selected. I think that Dokan plugin doesn't modify or manage the order, checkout, order confirmation and emails, so this issue is related to how it WooCommerce works. As you know, by default Woocommerce show the name of the method, in this case local pickup, but doesn't show the store address. I would like to have this feature, and display this valuable information in the order, checkout, emails, and invoices. I found the following code but display what I want in each order line, and I would like to display and integrate as a local pickup method description:

add_action( 'woocommerce_add_order_item_meta', 'dp_add_vendor_to_order_item_meta', 10, 2);
function dp_add_vendor_to_order_item_meta( $item_id, $cart_item) {      
        $vendor_id = $cart_item[ 'data' ]->post->post_author;
// build up address 
        $address1           = get_user_meta( $vendor_id , 'billing_address_1', true );
        $address2           = get_user_meta( $vendor_id , 'billing_address_2', true );
        $city               = get_user_meta( $vendor_id , 'billing_city', true ); 
        $store_postcode     = get_user_meta( $vendor_id , 'billing_postcode', true ); 
        $state              = get_user_meta( $vendor_id , 'billing_state', true ); 
        $address            = ( $address1 != '') ? $address1 .', ' . $city .', ' . $state.', '. $store_postcode :''; 
    
    wc_add_order_item_meta( $item_id, apply_filters('vendors_sold_by_in_email', __('Recoger en', 'vendors')), $address);
}
add_action( 'woocommerce_add_order_item_meta', 'email_add_vendor_to_order_item_meta', 10, 3);
function email_add_vendor_to_order_item_meta( $item_id, $cart_item) {       
       $vendor_id       = $cart_item[ 'data' ]->post->post_author;
       $email_vendor    = get_userdata( $vendor_id )->user_email;
    
    wc_add_order_item_meta( $item_id, apply_filters('vendors_sold_by_in_email', __('Email', 'vendors')), $email_vendor);
}

Can someone help me to fix this issue? I think this problem could affect many other users due the Covid-19, many stores want to serve their products with local pickup service. Thank you very much in advance, David

1 Answers1

0

I think the code below may be of use to you, keep in mind you need to change the shipping method ID to correspond with your shipping method

https://gist.github.com/drivenfaroff/86377bd208ab40e2a370185c47db8f5b

<?php

add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2 );

function add_order_email_instructions( $order, $sent_to_admin ) {

    $shipping_method = @array_shift( $order->get_shipping_methods() );
    $shipping_method_id = $shipping_method['method_id'];

    if ( ! $sent_to_admin ) {
        if ( 'local_pickup:5' == $shipping_method_id ) {
            // local pickup option
            echo '<p><strong>Instructions:</strong> Please contact us at 000-000-000 to arrange a pick-up time.</p>';
        } else {
            // other methods
            echo '';
        }
    }
}

?>

Edit: Based on the Comments below some extra information on how to find your shipping ID

Source: https://www.bolderelements.net/support/knowledgebase/finding-the-shipping-options-id/

Using Developer Tools in Google Chrome allows you to view specific sources of code, which can also reveal an option’s ID. Right click on the ‘Shipping’ box of your checkout page when the option you need is available. The option ID can be found nearby in the source code enter image description here

Jasper B
  • 851
  • 4
  • 13
  • Hi Jasper B, thank your very much. I don't know what is the shipping method id. Where I can find it? – David Perez Feb 11 '21 at 13:09
  • Hi, I just want to display the store address instead of the default "local pickup" that shows Woocommerce. Thank you very much for your kind help. – David Perez Feb 11 '21 at 13:12
  • And how to display on order, cart and order confirmation pages? – David Perez Feb 11 '21 at 13:16
  • I found this information: https://stackoverflow.com/questions/47340084/add-pickup-locations-custom-field-on-checkout-page-and-in-woocommerce-data-field. More or less is What I need/want, but instead of manage with a dropdown selector with manual addresses, use the vendor address. – David Perez Feb 11 '21 at 13:36
  • I added instructions for finding the ID in case you or anyone else may still needs to use this solution – Jasper B Feb 12 '21 at 15:53
  • Hi Jasper B, I've introduced the shipping_method_id, in my case is [0] and the local_pickup:1 what is my case and nothing is happening. It's like not working. – David Perez Feb 13 '21 at 11:10
  • I don't know why is so complicated to display the vendor addres instead of "local pickup" everywhere. The given code is only for emails not for order, checkout as I requested. – David Perez Feb 13 '21 at 11:49
  • Hi, can anybody help me to fix this issue? Thank you. – David Perez Feb 18 '21 at 09:10