大佬教程收集整理的这篇文章主要介绍了检查 WooCommerce 订单中是否至少有一项具有特定的属性术语,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想检查是否至少有一个项目在 WooCommerce 订单中具有特定的属性术语以在邮购中显示某些内容。
属性税是“pa_labels”,术语是“树”,但缺少某些东西...知道吗?
add_action( 'woocommerce_thankyou','webroom_check_product_attr_in_order',5 );
function webroom_check_product_attr_in_order( $order_ID ) {
if ( ! $order_ID ) {
return;
}
$order = wc_get_order( $order_ID );
$attr_in_order = false;
$items = $order->get_items();
foreach ( $items as $item ) {
$product_ID = $item['product_ID'];
if ( has_term( 'tree','pa_labels',$product_ID ) ) {
$attr_in_order = true;
break;
}
}
// Echo content only if $attr_in_order == true
if ( $attr_in_order ) {
add_action( 'woocommerce_email_customer_details','custom_woocommerce_email_customer_details',25);
}
}@H_419_10@
以上是大佬教程为你收集整理的检查 WooCommerce 订单中是否至少有一项具有特定的属性术语全部内容,希望文章能够帮你解决检查 WooCommerce 订单中是否至少有一项具有特定的属性术语所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。