Skip to content

Instantly share code, notes, and snippets.

@yousufansa
Created January 29, 2021 15:46
Show Gist options
  • Save yousufansa/4a8fad2691a74d2c0d725da8d363f609 to your computer and use it in GitHub Desktop.
Save yousufansa/4a8fad2691a74d2c0d725da8d363f609 to your computer and use it in GitHub Desktop.
WooCommerce - Adding <span> wrap on order item variation name
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