-
-
Save dexit/1527fc58c161ca268032db11b3b6bfa1 to your computer and use it in GitHub Desktop.
WooCommerce - Adding <span> wrap on order item variation name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( ! function_exists( 'around_wc_order_item_name' ) ) { | |
function around_wc_order_item_name( $name, $item ){ | |
$variation_id = $item['variation_id']; | |
if( $variation_id > 0 ) { | |
$product_id = $item['product_id']; | |
$_product = wc_get_product( $product_id ); | |
$product_name = $_product->get_title(); | |
$_name = $product_name; | |
$variation_name = str_replace( $product_name . ' -', '', $item->get_name() ); | |
$_name .= '<span class="your-class">' . $variation_name . '</span>'; | |
$updated_name = str_replace( $item->get_name(), $_name, $name ); | |
$name = $updated_name; | |
} | |
return $name; | |
} | |
} | |
add_filter( 'woocommerce_order_item_name', 'around_wc_order_item_name', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment