Support

Account

Home Forums General Issues Displaying values in woocommerce emails

Solving

Displaying values in woocommerce emails

  • I’ve set up a group to display in woocommere orders using POST TYPE equal to shop_order.

    I am trying to display the values in my completed order email. This is what I have in my template:

    $tracking 	= get_field('tracking-code');
    $carrier 	= get_field('carrier-name');
    $date 		= get_field('pickup_date');
    
    <p>Your order has been picked up by <?php echo $carrier; ?> on <?php echo $date; ?>. Your tracking code is <?php echo $tracking; ?>.</p>

    I suspect I am supposed to somehow declare the get_field fields are in the order pages.

    Also, for some reason, the date shows up, but it’s “yyyymmdd” even though in my settings I entered “dd/mm/yy”.

  • I can’t recall ever seeing a topic on trying to put acf values into emails, so this is just a guess. You probably need to include the post ID of where to get the value from, for example the post ID of the order post, and I don’t know if that information is available where you are generating the email. Does WC pass the order/post ID to the mail function?

    
    $tracking 	= get_field('tracking-code', $post_id);
    $carrier 	= get_field('carrier-name', $post_id);
    $date 		= get_field('pickup_date', $post_id);
    
    <p>Your order has been picked up by <?php echo $carrier; ?> on <?php echo $date; ?>. Your tracking code is <?php echo $tracking; ?>.</p>
    
  • Gotta use $order_id instead of $post_id.

    Also remember to triple check your field names…

  • The code above is not working in the admin-new-order.php template

    What am I missing?

    <?php
    
    $section 	= get_field( 'location_section', $order_id );
    $column 	= get_field( 'location_column', $order_id );
    $row 		= get_field( 'location_row', $order_id );
    
    ?>
    
    <p>Location of item is: <strong>S<?php echo $section; ?>-C<?php echo $column; ?>-R<?php echo $row; ?></strong></p>
    
    
  • @paul115
    on the email template, you need to get the order ID first, like:

    
    <?php
    $order_id = $order->id; 
    //then
    $section 	= get_field( 'location_section', $order_id );
    $column 	= get_field( 'location_column', $order_id );
    $row 		= get_field( 'location_row', $order_id );
    ?>
    <p>Location of item is: <strong>S<?php echo $section; ?>-C<?php echo $column; ?>-R<?php echo $row; ?></strong></p>
    
  • Good Cod And it work really well

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.