So I almost got it, but this last detail of specifying WooCommerce emails is leaving my head in a bit of a knot here.
I need to show ACF (advanced custom fields) fields of products (in this case it's a custom shipping time)
- But only in the new order email (processing order and waiting payment order sent to the client) and then new order email to admin.
This was the main way I found: "Display product ACF field value in Woocommerce transaction emails" Thank you in advance @LoicTheAztec
I also added some conditional settings to it (mind me my PHP is very beginning copy-pasty) which are working pretty well.
However what I can't get around is making it work only on new order emails. I have it setup like this, and it works, however it shows on all emails that contain the email order details, and I can't have the shipping time showing on the completed order emails as it will create confusion.
// Display product ACF custom field value shipping in email notification
add_filter( 'woocommerce_order_item_name', 'custom_order_item_name', 10, 2 );
function custom_order_item_name( $item_name, $item ) {
// Targeting email notifications only
if ( 'new_order' == $email->id )
return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
$othershipping = get_field( 'shipping_custom', $product->get_id());
if( $shpng_value = get_field('shipping_', $product->get_id())== "24h") {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping time', 'woocommerce' ) . ': </strong>' . '<p>Get it tomorrow(24h)</p>' . '</p>';
}
elseif( $shpng_value = get_field('shipping_', $product->get_id())== "2-5 days") {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping time', 'woocommerce' ) . ': </strong>' . '<p>2-5 days</p>' . '</p>';
}
elseif( $shpng_value = get_field('shipping_', $product->get_id())== "other") {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping time', 'woocommerce' ) . ': </strong>' . $othershipping . '</p>';
}
return $item_name;
}
I have tried switching the
if ( 'new_order' == $email->id )
to
if ( 'new_order' != $email->id )
But that just makes it not work anywhere.
I also thought it could be this part
function custom_order_item_name( $item_name, $item ) {
Where I need to add ($order, $sent_to_admin, $plain_text, $email )
function custom_order_item_name( $item_name, $item, $order, $sent_to_admin, $plain_text, $email )
But it makes the email return an error.