• Resolved beezwings

    (@beezwings)


    Hi! I’m trying to customize an email when a customer selects, “Local Pickup.”

    I tried adding this to my funtions.php

    add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2 );
    
    function add_order_email_instructions( $order, $sent_to_admin ) {
    
      if ( ! $sent_to_admin ) {
    
        if ( 'local_pickup' == $order->shipping_methods ) {
          // local pickup
          echo '<p><strong>Instructions:</strong> These are the local pickup instructions.</p>';
        } else {
          // other methods (ie table rates)
          echo '<p><strong>These are the instructions for everything else</p>';
        }
      }
    }

    But it doesn’t seem to be working 🙁

    Can someone suggest a fix?

    Thanks!

    https://wordpress.org/plugins/woocommerce/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Use

    $order->get_shipping_method()

    To get the method ID.

    Thread Starter beezwings

    (@beezwings)

    Thanks! Can you be super specific for the whole code? I’m a newbie (I had altered that code from something else).

    I tried

    function add_order_email_instructions( $order, $sent_to_admin ) {
    
      if ( ! $sent_to_admin ) {
    
        if ( 'local_pickup' == $order->get_shipping_method ) {
          // Local Pickup
          echo '<p><strong>Instructions:</strong> These are the local pickup instructions.</p>';
        } else {
          // other methods (ie table rates)
          echo '<p><strong>These are the instructions for everything else!</p>';
        }
      }
    }

    but that didn’t work either.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    $order->get_shipping_method

    is wrong.

    $order->get_shipping_method()

    is right. Try that.

    Thread Starter beezwings

    (@beezwings)

    It didn’t work 🙁 The email I received still says, “These are the instructions for everything else” rather than “These are the local pickup instructions”

    (PS: Thanks so much for the quick responses!)

    Plugin Contributor Mike Jolley

    (@mikejolley)

    if you simply add:

    echo $order->get_shipping_method();

    to your email, what do you get?

    Thread Starter beezwings

    (@beezwings)

    So, on another forum, someone said the following, but I don’t know how to implement that:

    There’s no shipping_method class member for the order abstract like that since there can be multiple methods per order (whereas there’s only one payment method per order). You’d need more additional code to get the array of shipping methods, then check to see if the method you want is in that array to add your notices.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    This is true, however the code I posted still works and returns the first found shipping method. You only have 1 per order so it doesn’t matter.

    Thread Starter beezwings

    (@beezwings)

    Hi, I tried that, but then the email just returns: “local pickup” but I don’t need the email to say that; I want the email to say, “The instructions for local pickup are come to this address between 2-4pm etc. …” when the person has selected local pickup.

    Thanks for your persistance.

    Jessie

    Plugin Contributor Mike Jolley

    (@mikejolley)

    This was just to see what was returned. If it says ‘local pickup’ use that string in your previous if/else statement.

    Thread Starter beezwings

    (@beezwings)

    Oh, wow! I just realized I had to use “Local Pickup” instead of “local_pickup” because it was looking for the actual output. Gee, thanks! So sorry it took so much back and forth, and I appreciate your patience. Have an awesome day!

    Plugin Contributor Mike Jolley

    (@mikejolley)

    There was an underscore before? Make sure the string matches what was echo’d.

    Also before you forgot to include the brackets for the function name.

    Thread Starter beezwings

    (@beezwings)

    (Just edited my previous response. Thanks a million!)

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Adding instructons for local pickup’ is closed to new replies.