0

My php days are long gone and I'm trying to achieve a "simple" customisation of the order email confirmation (processing and confirmed emails) sent to the customers of a Woocommerce webshop using the latest available (self-hosted) versions of WP (6.5.3) and Woo (8.8.3).

My products are mostly variable ones using 2 attributes. "Duration" & "Location" (Lieu in screenshot below).

What I'm trying to achieve is adding for each product of the order, the product attribute Description right under the (currently displayed) product attribute Name.

enter image description here

The name being the city name and the description being the detailed address.

I want to add this php function using Code Snippets (plugin) to avoid having to mess with the php files of the theme.

I've stumbled upon lots of different (outdated) solutions and tried to adapt a few of these to achieve this.

add_action( 'woocommerce_order_item_meta_start',                 'add_addres_to_email', 10, 3 );
function add_addres_to_email( $item_id, $item, $order ) {
// Set below your product attribute taxonomy (always starts with "pa_")
$taxonomy = 'pa_lieu';

// On email notifications
if ( ! is_wc_endpoint_url() && $item->is_type('line_item') ) {
    $product    = $item->get_product();

    if ( $term_names = $product->get_attribute( $taxonomy ) ) {
     echo '<br/><small>' . nl2br( $term_names ) . '</small>';
    }
}
}

Unfortunately, this only works with the Name and not the description. And adds it under the product name instead of after the product Locatin marked with the arrow on the screenshot provided.

How can this be placed at this exact spot?

Is there a way to replace $term_names with $term_descriptions that would work?

I tried this but came out empty in the email while the content is filled in in the backoffice.

Appreciate your help.

1
  • Anyone really???
    – Greg Vdo
    Commented May 19 at 12:50

0

Browse other questions tagged or ask your own question.