用管道替换 WooCommerce 购物车项目变体标题中的某个字符
Replace a certain character in WooCommerce cart item variations title by a pipe
如何在结帐时删除产品属性的逗号分隔符。
示例:
Blue Black Raw Denim - 37, Slimfit
37 是属性产品,slimfit 是模型产品我要删除逗号或替换为 |
。我该怎么做?
购物车代码如下:
<td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
<?php
if ( ! $product_permalink ) {
echo apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . ' ';
} else {
echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key );
}
如果我删除这部分项目的产品名称和属性将会消失,而不是消失。
我想用 |
...
替换逗号
我怎样才能做到这一点?
谢谢
参考图片:
所以你应该使用挂钩在 woocommerce_cart_item_name
过滤器挂钩中的自定义函数,你将使用 [=12 用管道替换彗差=]php函数,这样:
// Tested on WooCommerce version 3+
add_filter( 'woocommerce_cart_item_name', 'custom_item_name', 10, 3 );
function custom_item_name( $item_name, $cart_item, $cart_item_key ){
$new_item_name = str_replace(',', ' |', $item_name);
return $new_item_name;
}
代码进入您的活动 child 主题(或主题)的 function.php 文件或任何插件文件。
此代码已经过测试并且可以工作。它将用购物车和结帐项目标题中的管道替换昏迷。
如何在结帐时删除产品属性的逗号分隔符。
示例:
Blue Black Raw Denim - 37, Slimfit
37 是属性产品,slimfit 是模型产品我要删除逗号或替换为 |
。我该怎么做?
购物车代码如下:
<td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
<?php
if ( ! $product_permalink ) {
echo apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . ' ';
} else {
echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key );
}
如果我删除这部分项目的产品名称和属性将会消失,而不是消失。
我想用 |
...
我怎样才能做到这一点?
谢谢
参考图片:
所以你应该使用挂钩在 woocommerce_cart_item_name
过滤器挂钩中的自定义函数,你将使用 [=12 用管道替换彗差=]php函数,这样:
// Tested on WooCommerce version 3+
add_filter( 'woocommerce_cart_item_name', 'custom_item_name', 10, 3 );
function custom_item_name( $item_name, $cart_item, $cart_item_key ){
$new_item_name = str_replace(',', ' |', $item_name);
return $new_item_name;
}
代码进入您的活动 child 主题(或主题)的 function.php 文件或任何插件文件。
此代码已经过测试并且可以工作。它将用购物车和结帐项目标题中的管道替换昏迷。