sisi
sisi

Reputation: 167

How do I just display the value for the variations in woocommerce email?

How do I just display the value for the variations in woocommerce email? Right now it's displaying the label and value. It's display like this -> Size: M But I want to display only the value "M" Also, how do I remove the ":" ?

        <td class="td" style="text-align: right; vertical-align:middle; font-family: 'Courier New', 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace;">
            <?php if ( ! empty( $item_meta->meta ) ) {
                echo nl2br( $item_meta->display( true, true, '_', "\n" ) );
            } ?>
        </td>

Upvotes: 0

Views: 1397

Answers (1)

Scriptonomy
Scriptonomy

Reputation: 4055

Woocommerce uses a class called WC_Order_Item_Meta to display order item meta. It is used by Woocommerce email-order-items.php template.

Add a woocommerce_order_items_meta_displayfilter:

add_filter( 'woocommerce_order_items_meta_display'

Inject two dependencies $output and $obj:

function ($output, $obj) {...}, 10, 2);

Check if order item is of variable type:

if ($obj->product->parent->product_type == 'variable'){

Scrub the output:

ltrim(explode(':', $output)[1])

In conclusion, this is what the code looks like:

add_filter( 'woocommerce_order_items_meta_display', function ($output, $obj) {
if($obj->product->parent->product_type == 'variable') {
    $output = ltrim(explode(':', $output)[1]);
}
return $output; },10,2);

Upvotes: 3

Related Questions