woocommerce - 修改购物车和结帐表中的产品名称
问题描述
TL;博士
我想在购物车和结帐时都更改产品名称,因此会显示属性名称的名称。
就像现在一样:我的产品名称 - 蓝色
如我所愿:我的产品名称 - 颜色:蓝色
细节
我可以在案例中看到,正是这些行打印了它:
<td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
<?php
if ( ! $product_permalink ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . ' ' );
} else {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
}
do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );
// Meta data.
echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok.
// Backorder notification.
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>', $product_id ) );
}
?>
</td>
我在这里找到了另一个帖子:Add Product ID after the cart item,建议如下:
add_filter( 'woocommerce_cart_item_name', 'just_a_test', 10, 3 );
function just_a_test( $item_name, $cart_item, $cart_item_key ) {
// Display name and product id here instead
echo $item_name.' ('.$cart_item['product_id'].')';
}
..但这附加到产品名称。我想修改现有的。
解决方案尝试 1
我在这里找到了解决方法。
这是:
add_filter( 'woocommerce_product_variation_title_include_attributes', '__return_false' );
add_filter( 'woocommerce_is_attribute_in_product_name', '__return_false' );
理想情况下,我想控制自己,如何显示每个变化。所以这不是一个完整的修复,而是朝着正确方向迈出的一步。
额外问题我自己怎么能找到这两个过滤器?
我在购物车的 WooCommerce 代码中看不到它们
解决方案
推荐阅读
- java - 我可以在从同步块返回对象之前调用 notifyAll 吗?
- python - 定期轮询 Raspberry Pi 上的端口或硬件 IO 点
- c# - 当路径包含“&”时,安装 VSTO Outlook 加载项失败
- javascript - 使用数组作为对象的替代方法是什么?
- intellij-idea - 运行 IntelliJ Run 配置后触发多个 URL
- javascript - 为什么 .push() 为我在数组中创建数组?
- reactjs - 如何将 ref 传递给类函数
- java - java中所有类型文件的加密解密AES
- python-3.x - 这是如何工作的 str.replace(r'\(.*\)', '')?
- vb.net - 将属性值绑定到 Label.Text VB.Net