[英]Conditional WooCommerce email notification footer based on categories of products ordered
对于 Stack Overflow 的好人,
I'm trying to create an "Upgrade Safe" way (as a function in my Theme's functions.php file) of customising the footer of the standard WooCommerce email notification email that customers receive when placing orders.
我想要实现的是在订购特定类别的产品时向所述 email 页脚添加自定义文本,但老实说,我在为这些类别进行 in_array 测试时遇到了一些困难,我很确定我还没有完全正确!
如果你们中的任何人对我哪里出错有任何指示,我将永远感激不尽!
function farm_shop_woocommerce_email_footer( $order, $sent_to_admin, $plain_text, $email ) {
$items = $order->get_items();
foreach ( $items as $item ) {
$terms = wp_get_post_terms( $item['product_id'], 'product_cat' );
foreach($terms as $term){
$term_names[] = $term->name; // Product cat Name
//$term->term_id; Product cat Id
//$term->slug; Product cat slug
}
}
if ( in_array('Farm Shop', 'Cowdray Kitchen', 'Cowdray Living', 'The Meditator', 'Cowdray Hampers', 'Cowdray Supper Kits', 'Grocery', 'Butchery', 'Deli', 'Pantry', 'Houseplants and Flowers', 'Picnic Hampers', 'Afternoon Tea', 'Drinks', 'Wreaths', $term_names) ) {
echo 'Cowdray Farm Shop Ltd<br>VAT Number: 970407718';
}
};
add_action( 'woocommerce_email_footer', 'farm_shop_woocommerce_email_footer', 10, 4 );
我注意到您没有正确使用 in_array :
你能像这个例子一样把你的字符串集放在一个数组中 -> 密切注意“数组('x','y')”:
if (in_array(array('x', 'y'), $yourTermsArray)) {
echo 'something matched';
}
据我所知,将术语数组放在一起看起来很准确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.