• Resolved darkmatter661

    (@darkmatter661)


    I’d like to include the PO Number field in a custom email notification (non-Woocommerce generated). Can you assist with the field name and how to call it?

    I found:

    $po_number = get_post_meta($order->get_id(), Plugin_Constants::Purchase_Order_Number, true);
    if ($po_number && get_option('igfw_enable_purchase_order_number') == 'yes') {
                        if ($plain_text) {
                            echo sprintf("\nPurchase Order Number: %s\n", $po_number);
                        } else {
                            echo '<p>' . sprintf("\nPurchase Order Number: %s\n", $po_number) . '</p>';

    Can this be used in any snippet?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hello – I would also like to add the PO number to the customer’s email. I can see it on the Admin notification email which is great but my customers will also need their PO on their order conformation. How can I add this please?

    Thread Starter darkmatter661

    (@darkmatter661)

    Anyone on this question?

    Hi @darkmatter661 @gordonlangley

    Please add this code on your child-theme/themes functions.php to display the purchase number in your customer’s email notification.

    /**
     * Add a custom field (in an order) to the emails
     */
    add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
    
    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
        $fields['igfw_purchase_order_number'] = array(
            'label' => __( 'PO #' ),
            'value' => get_post_meta( $order->id, 'igfw_purchase_order_number', true ),
        );
        return $fields;
    }

    Woocommerce reference link here.

    Admin email: https://prnt.sc/TAjuzpSvkMnL
    Customer email: https://prnt.sc/6FCtV3Ro2XwN

    That’s amazing thank you Sheena – is there a way to make it appear higher up in the email? So it’s the first item in the order content next to the normal order number. Also – It is appearing twice in the ‘New order’ email notification – Is there a way to only show it once – at the top of the order details on both emails.

    Thank you so much!!

    Admin email

    Customer email

    Hi @gordonlangley

    Kindly replace the code above with this code snippet below:

    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 ) {
            $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
            $po = get_post_meta( $order_id , 'igfw_purchase_order_number', true );
            if( ! empty($po) )
                echo '<p><strong>Purchase Order Number:</strong> ' . $po. '</p>'; 
        } 
    }

    The custom field can be seen above the order table and won’t send to the admin email to avoid the duplication.

    Reference link here.

    Customer Email: https://prnt.sc/6WQ3fb0UyUeZ

    Thread Starter darkmatter661

    (@darkmatter661)

    @sdeoduco Thank you so much!!

    Any reason I can’t add this to an existing snippet I run with a custom email script?

    Hi @darkmatter661

    Sorry for the slow response.

    Were you able to retrieve the order ID? Could you try the snippet below and add this into your custom email:

    //Woo retrieve order ID
    global $woocommerce, $post;
    $order = new WC_Order($post->ID);
    $order_id = $order->get_id();
    
    //then display the PO fieldname 
    $po = get_post_meta( $order_id , 'igfw_purchase_order_number', true );
    if( ! empty($po) )
        echo '<p><strong>Purchase Order Number:</strong> ' . $po. '</p>'; 
    }

    Reference link.

    Unfortunately, the hook above this thread only works on Woocommerce emails.

    Thread Starter darkmatter661

    (@darkmatter661)

    Thank you Sheena! I’m not using the default WC emails for order notifications. This is what I have for that, as a snippet:

    add_action('woocommerce_thankyou', 'action_checkout_order_processed', 10, 1);
    function action_checkout_order_processed( $order_id ) {
    // get an instance of the order object
    $order = wc_get_order( $order_id );
    global $woocommerce;
    $prodhtml="<br><b>Product Details</b> <br>";
    foreach ( $order->get_items() as $item_id => $item ) {
    $product_id = $item->get_product_id();
    $itemsbox=get_post_meta($product_id,'itemsbox',true);
    $prodhtml.="Product Name : ".$item->get_name()."<br>";
    $prodhtml.="Product Qty : ".$item->get_quantity()."<br>";
    $variation_id = $item->get_variation_id();
    
    if($variation_id) {
    $prodhtml.="Product SKU : ".get_post_meta( $variation_id, '_sku', true )."<br>";
    }
    else
    {
    $prodhtml.="Product SKU : ".get_post_meta( $product_id, '_sku', true )."<br>";
    }
    
    $prodhtml.="Custom Slug : ".$order->get_meta('ref_custom_slug')."<br>";
    $prodhtml.="Sales Rep : ".$order->get_meta('ref_affiliate_name')."<br>";
    $prodhtml.="<br>";
    
    }
    
    $mailer = $woocommerce->mailer();
    $html='';
    $html.="<h3 style='text-align:center'>J2 Medical Supply Pick Ticket</h3><b>Order Details</b> : <br>";
    $html.="Order Id: ".$order_id."<br>";
    $html.="First Name: ".$order->get_shipping_first_name()."<br>";
    $html.="Last Name: ".$order->get_shipping_last_name()."<br>";
    $html.="Company: ".$order->get_shipping_company()."<br>";
    $html.="Payment Method: ".$order->get_payment_method_title()."<br>";
    
    //THIS IS WHERE I'D LIKE TO PLACE THE PO NUMBER
    
    $html.="<br><b>Order Amount</b>: <br>";
    $html.="Total before tax/shipping: $".$order->get_subtotal()."<br>";
    $html.="<br><b>Shipping Address</b> : <br>";
    $html.="Address: ".$order->get_shipping_address_1()."<br>";
    $html.="City: ".$order->get_shipping_city()."<br>";
    $html.="State: ".$order->get_shipping_state()."<br>";
    $html.="Zipcode: ".$order->get_shipping_postcode()."<br>";
    $html.="Shipping Method: ".$order->get_shipping_method()."<br>";
    $shipping = $order->get_shipping_total();
    $html.="Shipping Cost: $".$order->get_shipping_total()."<br>";
    $html.=$prodhtml;
    $headers = "From: J2 Medical Supply <[email protected]>\n";
    $message = $mailer->wrap_message(
    
    // // Message head and message body.
    sprintf( __( 'Order %s received' ), $order->get_order_number() ), $html );
    
    // Client email, email subject and message.
    $mailer->send('[email protected]', sprintf( __( 'New Order #%s Pick Ticket' ), $order_id ), $html,$headers );
    }

    See above where I’d like to add the PO number but everything I’ve tried breaks the email being sent.

    @darkmatter661

    Thanks for providing your snippet. I reused it and managed to display the PO number.
    Please try this one on your functions.php

    add_action('woocommerce_thankyou', 'action_checkout_order_processed', 10, 1);
    function action_checkout_order_processed( $order_id ) {
    // get an instance of the order object
    $order = wc_get_order( $order_id );
    global $woocommerce;
    $prodhtml="<br><b>Product Details</b> <br>";
    foreach ( $order->get_items() as $item_id => $item ) {
    $product_id = $item->get_product_id();
    $itemsbox=get_post_meta($product_id,'itemsbox',true);
    $prodhtml.="Product Name : ".$item->get_name()."<br>";
    $prodhtml.="Product Qty : ".$item->get_quantity()."<br>";
    $variation_id = $item->get_variation_id();
    //then display the PO fieldname 
    $po = get_post_meta( $order->get_id() , 'igfw_purchase_order_number', true );
    
    if($variation_id) {
    $prodhtml.="Product SKU : ".get_post_meta( $variation_id, '_sku', true )."<br>";
    }
    else
    {
    $prodhtml.="Product SKU : ".get_post_meta( $product_id, '_sku', true )."<br>";
    }
    
    $prodhtml.="Custom Slug : ".$order->get_meta('ref_custom_slug')."<br>";
    $prodhtml.="Sales Rep : ".$order->get_meta('ref_affiliate_name')."<br>";
    $prodhtml.="<br>";
    
    }
    
    $mailer = $woocommerce->mailer();
    $html='';
    $html.="<h3 style='text-align:center'>J2 Medical Supply Pick Ticket</h3><b>Order Details</b> : <br>";
    $html.="Order Id: ".$order_id."<br>";
    $html.="First Name: ".$order->get_shipping_first_name()."<br>";
    $html.="Last Name: ".$order->get_shipping_last_name()."<br>";
    $html.="Company: ".$order->get_shipping_company()."<br>";
    $html.="Payment Method: ".$order->get_payment_method_title()."<br>";
    //THIS IS WHERE I'D LIKE TO PLACE THE PO NUMBER
    if( ! empty($po) ) {
    $html.="Purchase Order Number: ".$po."<br>";
    }
    
    $html.="<br><b>Order Amount</b>: <br>";
    $html.="Total before tax/shipping: $".$order->get_subtotal()."<br>";
    $html.="<br><b>Shipping Address</b> : <br>";
    $html.="Address: ".$order->get_shipping_address_1()."<br>";
    $html.="City: ".$order->get_shipping_city()."<br>";
    $html.="State: ".$order->get_shipping_state()."<br>";
    $html.="Zipcode: ".$order->get_shipping_postcode()."<br>";
    $html.="Shipping Method: ".$order->get_shipping_method()."<br>";
    $shipping = $order->get_shipping_total();
    $html.="Shipping Cost: $".$order->get_shipping_total()."<br>";
    $html.=$prodhtml;
    $headers = "From: J2 Medical Supply <[email protected]>\n";
    $message = $mailer->wrap_message(
    
    // // Message head and message body.
    sprintf( __( 'Order %s received' ), $order->get_order_number() ), $html );
    
    // Client email, email subject and message.
    $mailer->send('[email protected]', sprintf( __( 'New Order #%s Pick Ticket' ), $order_id ), $html,$headers );
    }

    Custom email output: https://prnt.sc/Lj6OuVfH7ij4

    Hopefully this works on you ??

    Thread Starter darkmatter661

    (@darkmatter661)

    Thanks Sheena I’ll check it out!

    Side question…. have you ever heard of the ability to use multiple payment gateways/methods in one checkout transaction, based on factors such as the products in the cart? For example, Product A is sold strictly via PO Number (such as with your plugin) but Product B in same transaction requires payment via credit card… I wonder if this is even possible with WC.

    Hi @darkmatter661

    Sorry have nothing in particular.

    You might need to explore plugins that has product restriction on the checkout process.

    If you have no other concerns. We’ll close off this thread ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Recall PO Number field in email’ is closed to new replies.