【发布时间】:2020-04-08 02:21:09
【问题描述】:
使用以下功能,我将自定义字段应用于添加到 Woocommerce 购物车和结帐页面的产品,以及订单和通知电子邮件。
我的问题是如何在购物车、结帐等产品标题上方显示品牌。任何帮助将不胜感激。
// Display 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']; // Get the WC_Product Object
if ( $value = $product->get_meta('my_custom_field') ) {
$product_name .= '<span class="custom_field_class">'.$value.'</span>';
}
return $product_name;
}
// Display in orders and email notifications
add_filter( 'woocommerce_order_item_name', 'customizing_order_item_name', 10, 2 );
function customizing_order_item_name( $product_name, $item ) {
$product = $item->get_product(); // Get the WC_Product Object
if ( $value = $product->get_meta('my_custom_field') ) {
$product_name .= '<span class="custom_field_class">'.$value.'</span>';
}
return $product_name;
}
【问题讨论】:
-
您想显示从数据库中获取的值以显示在购物车、结帐和电子邮件中吗?
-
正确,我想显示从数据库中获取的字段值,以显示在购物车、结帐、电子邮件和订单中。
标签: php wordpress woocommerce advanced-custom-fields hook-woocommerce