Home » Wordpress » How to remove price from Woocommerce Email

How to remove price from Woocommerce Email

Posted by: admin November 30, 2017 Leave a comment

Questions:

I am trying to develop a plugin that send the customer a “gift receipt” upon completing an order. I have everything working perfectly except I am unable to strip the price from the emails. When I try to edit the email-order-items.php template and remove the price column then the emails come in blank.

Specifically this is for downloadable products so the download links no longer show when I make any edits to the email-order-items file. And I would only want it to strip the price from the gift receipt emails not the other emails.

What I have done:
in my plugin I call on a email template “customer-gift-receipt.php” which is pretty much the same as “customer-processing-order.php” that comes package with Woocommerce.

In the file there is this line that brings in the email-order-items template and shows the links and price

<?php echo $order->email_order_items_table( $order->is_download_permitted(), 
     true, ($order->status=='processing') ? true : false ); ?>

This is the email-order-items template.

No matter what I do I cannot seem to get those prices stripped from just the customer-gift-receipt.php emails. Specifically it is this line in the above template:

<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">
    <?php echo $order->get_formatted_line_subtotal( $item ); ?>
</td>

I tried creating a duplicate of the email-order-items template and removing that line then calling it in my plugin and that did not work. I also tried copying the email-order-items template inside of the customer-gift-receipt.php file in the appropriate section and that failed as well. I had to define $items = $order->get_items(); when I tried copying email-order-items directly into the customer-gift-receipt template for it to somewhat work.

So can anyone suggest a way for me to strip the prices out of my customer-gift-receipt templates?

I have checked through these links:

Class WC_Order

Class WC_Email_Customer_Processing_Order


UPDATE:
I just found this link which should help me bring in email_order_items_table outside of the class: https://gist.github.com/mikejolley/1965842
When I try to add the above code in my customer-email-receipt template and place an order I get this error:

Fatal error: Class 'order_item_meta' not found in 
   .../.../.../.../woocommerce/emails/customer-gift-receipt.php on line 41"
Answers:

Disable e-mail order items table from e-mail template and copy the function as a custom function into your theme.

<tbody>
    <?php //echo $order->email_order_items_table( $order->is_download_permitted(), true, ($order->status=='processing') ? true : false ); 
    echo custom_order_table($order);
    ?>
</tbody>

I had to remove download and variations which causes *Fatal Error with Class ‘order_item_meta’* error. So your custom function will look like:

       function custom_order_table($order,$price = false) {

        foreach($order->get_items() as $item) : 

        $_product = $order->get_product_from_item( $item );

        $file = $sku = $variation = $image = '';

        if ($show_image) :
          $src = wp_get_attachment_image_src( get_post_thumbnail_id( $_product->id ), 'thumbnail');
          $image = apply_filters('woocommerce_order_product_image', '<img src="'.$src[0].'" alt="Product Image" height="'.$image_size[1].'" width="'.$image_size[0].'" style="vertical-align:middle; margin-right: 10px;" />', $_product);
        endif;

        if ($show_sku && $_product->get_sku()) :
          $sku = ' (#' . $_product->get_sku() . ')';
        endif;


        $return .= '<tr>
          <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">'. $image . apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $sku . $file . $variation . '</td>
          <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">'.$item['qty'].'</td>';
        if ($price):
          $return .= '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">';

            if ( $order->display_cart_ex_tax || !$order->prices_include_tax ) : 
              $ex_tax_label = ( $order->prices_include_tax ) ? 1 : 0;
              $return .= woocommerce_price( $order->get_line_subtotal( $item ), array('ex_tax_label' => $ex_tax_label ));
            else :
              $return .= woocommerce_price( $order->get_line_subtotal( $item, true ) );
            endif;

          $return .= '</td>';
        endif;
        $return .= '</tr>';

        // Show any purchase notes
        if ($show_purchase_note) :
          if ($purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) :
            $return .= '<tr><td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . apply_filters('the_content', $purchase_note) . '</td></tr>';
          endif;
        endif;

      endforeach;

      echo $return;
      }