admin管理员组文章数量:1122832
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.
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.
本文标签: phpUsing WooCommerce Hooks to add product attribute descriptions to customer order email
版权声明:本文标题:php - Using WooCommerce Hooks to add product attribute descriptions to customer order email 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307463a1933319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论