Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from yousufansa/functions.php
Created December 16, 2024 16:31
Show Gist options
  • Save dexit/1527fc58c161ca268032db11b3b6bfa1 to your computer and use it in GitHub Desktop.
Save dexit/1527fc58c161ca268032db11b3b6bfa1 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