【发布时间】:2019-08-27 15:39:11
【问题描述】:
在 WooCommerce 中,我启用了 Perfect Brands Woocommerce 插件来显示产品品牌。我希望品牌在整个周期(单个产品页面、购物车、结帐、迷你购物车、订单和电子邮件)中出现在产品名称之前。
我可以在购物车和结帐页面中的产品名称之前显示相关品牌,使用 "Adding Woocommerce Brands names to cart item product names" 回答代码轻微更改 (使用 pbw-brand 插件自定义分类) :
// Display product brand in Cart and checkout pages
add_filter( 'woocommerce_cart_item_name', 'customizing_cart_item_name', 10, 3 );
function customizing_cart_item_name( $product_name, $cart_item, $cart_item_key ) {
$product = $cart_item['data']; // The product
$product_id = $cart_item['product_id']; // The product id
// Loop through the product brand names
foreach( wp_get_post_terms( $product_id, 'pwb-brand' ) as $wp_term )
$brand_names[] = $wp_term->name; // Set the brand names in an array
$brand_names_str = implode( ', ', $brand_names); // Set the brand names in a comma separated string array
$brand = $brand_names_str;
$product_permalink = $product->get_permalink( $cart_item );
if ( is_cart() && count( $brand_names ) > 0 )
return sprintf( '<a href="%s">%s %s</a>', esc_url( $product_permalink ), $brand, $product->get_name() );
elseif ( count( $brand_names ) > 0 )
return $brand . ' ' . $product_name;
else return $product_name;
}
但我不知道如何为订单和电子邮件通知实现这一点。
【问题讨论】:
标签: php wordpress woocommerce orders taxonomy-terms