How to remove a comma separation from product attribute on my checkout.
Example:
Blue Black Raw Denim - 37, Slimfit
37 is attribute product and slimfit is model product I want remove comma or replace with |
. how can I do that?
For cart code like this :
<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 );
}
If I delete this part item product name and attribute will gone but instead gone.
I want replace comma with a |
...
How can I achieve this?
Thanks
So you should use a custom function hooked in woocommerce_cart_item_name
filter hook, where you will replace the coma by a pipe using str_replace()
php function, this way:
// 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;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works. It will replace the coma by a pipe in cart and checkout items title.
Related answer: WooCommerce 3.0 - hide variation info in product title