WordPress: WooCommerce email_order_items_table remove price

admin

Administrator
Staff member
I’m new to PHP and also new to WooCommerce.
I want to edit the <a href="https://wordpress.org/plugins/woo-custom-emails/" rel="nofollow noreferrer">woo-custom-emails</a> plugin.
As a user I have the possibility to set
Code:
{email_order_items_table}
in my text which outputs the product name, followed by its quantity, followed by the price. I want to remove the price!

Here is what it does in code:

Code:
    // file: my_plugin/admin/class-wcemails-instance.php

    $this-&gt;find[]    = '{email_order_items_table}';
    $this-&gt;replace[] = $this-&gt;object-&gt;email_order_items_table();

here is what the that function does:

Code:
    // file: woocommerce/includes/abstracts/abstract-wc-order.php

/**
 * Output items for display in html emails.
 *
 * @param array $args Items args.
 * @param null $deprecated1 Deprecated arg.
 * @param null $deprecated2 Deprecated arg.
 * @param null $deprecated3 Deprecated arg.
 * @param null $deprecated4 Deprecated arg.
 * @param null $deprecated5 Deprecated arg.
 * @return string
 */
public function email_order_items_table( $args = array(), $deprecated1 = null, $deprecated2 = null, $deprecated3 = null, $deprecated4 = null, $deprecated5 = null ) {
    ob_start();

    if ( ! is_null( $deprecated1 ) || ! is_null( $deprecated2 ) || ! is_null( $deprecated3 ) || ! is_null( $deprecated4 ) || ! is_null( $deprecated5 ) ) {
        _deprecated_argument( __FUNCTION__, '2.5.0' );
    }

    $defaults = array(
        'show_sku'      =&gt; false,
        'show_image'    =&gt; false,
        'image_size'    =&gt; array( 32, 32 ),
        'plain_text'    =&gt; false,
        'sent_to_admin' =&gt; false
    );

    $args     = wp_parse_args( $args, $defaults );
    $template = $args['plain_text'] ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php';

    wc_get_template( $template, apply_filters( 'woocommerce_email_order_items_args', array(
        'order'               =&gt; $this,
        'items'               =&gt; $this-&gt;get_items(),
        'show_download_links' =&gt; $this-&gt;is_download_permitted() &amp;&amp; ! $args['sent_to_admin'],
        'show_sku'            =&gt; $args['show_sku'],
        'show_purchase_note'  =&gt; $this-&gt;is_paid() &amp;&amp; ! $args['sent_to_admin'],
        'show_image'          =&gt; $args['show_image'],
        'image_size'          =&gt; $args['image_size'],
        'plain_text'          =&gt; $args['plain_text'],
        'sent_to_admin'       =&gt; $args['sent_to_admin']
    ) ) );

    return apply_filters( 'woocommerce_email_order_items_table', ob_get_clean(), $this );
}

and that is the template:

Code:
    // file: woocommerce/templates/emails/email-order-items.php

&lt;?php
/**
 * Email Order Items
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-items.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates/Emails
 * @version     2.1.2
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

foreach ( $items as $item_id =&gt; $item ) :
    $_product     = apply_filters( 'woocommerce_order_item_product', $order-&gt;get_product_from_item( $item ), $item );
    $item_meta    = new WC_Order_Item_Meta( $item, $_product );

    if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
    ?&gt;
    &lt;tr class="&lt;?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?&gt;"&gt;
        &lt;td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"&gt;&lt;?php

            // Show title/image etc
            if ( $show_image ) {
                echo apply_filters( 'woocommerce_order_item_thumbnail', '&lt;div style="margin-bottom: 5px"&gt;&lt;img src="' . ( $_product-&gt;get_image_id() ? current( wp_get_attachment_image_src( $_product-&gt;get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /&gt;&lt;/div&gt;', $item );
            }

            // Product name
            echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );

            // SKU
            if ( $show_sku &amp;&amp; is_object( $_product ) &amp;&amp; $_product-&gt;get_sku() ) {
                echo ' (#' . $_product-&gt;get_sku() . ')';
            }

            // allow other plugins to add additional product information here
            do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );

            // Variation
            if ( ! empty( $item_meta-&gt;meta ) ) {
                echo '&lt;br/&gt;&lt;small&gt;' . nl2br( $item_meta-&gt;display( true, true, '_', "\n" ) ) . '&lt;/small&gt;';
            }

            // File URLs
            if ( $show_download_links ) {
                $order-&gt;display_item_downloads( $item );
            }

            // allow other plugins to add additional product information here
            do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text );

        ?&gt;&lt;/td&gt;
        &lt;td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"&gt;&lt;?php echo apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ); ?&gt;&lt;/td&gt;
        &lt;td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"&gt;&lt;?php echo $order-&gt;get_formatted_line_subtotal( $item ); ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php
}

if ( $show_purchase_note &amp;&amp; is_object( $_product ) &amp;&amp; ( $purchase_note = get_post_meta( $_product-&gt;id, '_purchase_note', true ) ) ) : ?&gt;
    &lt;tr&gt;
        &lt;td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"&gt;&lt;?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;?php endif; ?&gt;



I could replace the template as described in the comments BUT that would overwrite all emails to hide the price and I actually want to keep the price in all other emails that are not send through the plugin. I have no idea on how to make this conditional.

So here is my question: <strong>How can I hook that
Code:
email_order_items_table()
function to not output the price?</strong>

<em>PS: How can I see what is inside
Code:
$this-&gt;object
or how can I output in a human readable form everything inside the
Code:
$this
object?</em>