Support » Plugin: WooCommerce » Order product count without “x 1” ?

  • Resolved kitelab

    (@kitelab)


    Hi all, we would like to show the number (product quantity) of products in checkout and emails only if it’s greater than one.

    Especially in emails (plain text in our case), the “product x 1” is superfluous and ugly. From “x 2” is meaningful. Most of our products are sold once per order.

    Currently it’s like this:
    Kite: the urban ninja x 1
    Flying-line: zero.5 x 3

    We would like this:
    Kite: the urban ninja
    Flying-line: zero.5 x 3

    Appreciating any help, dirty hacks are welcome.

    Thank you, have a marvelous flight … Thomas

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    Best way to edit WooCommerce Email templates is: copy template PHP file, what you want to edit, from wp-content/plugins/woocommerce/templates/emails/plain to your child theme folder: wp-content/themes/child-theme/woocommerce/emails/plain and edit it here.

    Take a look at the following code line
    https://github.com/woocommerce/woocommerce/blob/ac15fa6e5fa677174fd14d0269b0985be3b0d197/templates/emails/plain/email-order-items.php#L37

    I currently do not have the option to test this but with an if statement you can determine the output.

    Maybe you can get started with this?

    And there you go

    replace

    		echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false );
    		if ( $show_sku && $sku ) {
    			echo ' (#' . $sku . ')';
    		}
    		echo ' X ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item );
    		echo ' = ' . $order->get_formatted_line_subtotal( $item ) . "\n";

    with

    		echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false );
    		if ( $show_sku && $sku ) {
    			echo ' (#' . $sku . ')';
    		}
    		
    		if($item->get_quantity() <= 1) {
    			echo ' ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item );			
    		} else {
    			echo ' X ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item );			
    		}
    
    		echo ' = ' . $order->get_formatted_line_subtotal( $item ) . "\n";

    Gr

    Thread Starter kitelab

    (@kitelab)

    Thank you very much, great.
    I made this one thanks to your help, and it’s perfect for us and our plain text emails, which are so much better on mobile:

    echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false );
    		if ( $show_sku && $sku ) {
    			echo ' (#' . $sku . ')';
    		}
    		
    		if($item->get_quantity() <= 1) {
    		echo ' = ' . $order->get_formatted_line_subtotal( $item ) . "\n";
    
    		} else {
    			echo ' x ' . apply_filters( 'woocommerce_email_order_item_quantity', $item->get_quantity(), $item );			
    			echo ' = ' . $order->get_formatted_line_subtotal( $item ) . "\n";
    		}

    Btw. pipes instead of “x” and “=” look also good. And of course the “x” is now lowercase 🙂

    Thanks again, enjoy your marvelous flight … Thomas

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order product count without “x 1” ?’ is closed to new replies.