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
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:
here is what the that function does:
and that is the template:
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
function to not output the price?</strong>
<em>PS: How can I see what is inside
or how can I output in a human readable form everything inside the
object?</em>
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}
Here is what it does in code:
Code:
// file: my_plugin/admin/class-wcemails-instance.php
$this->find[] = '{email_order_items_table}';
$this->replace[] = $this->object->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' => false,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => false,
'sent_to_admin' => 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' => $this,
'items' => $this->get_items(),
'show_download_links' => $this->is_download_permitted() && ! $args['sent_to_admin'],
'show_sku' => $args['show_sku'],
'show_purchase_note' => $this->is_paid() && ! $args['sent_to_admin'],
'show_image' => $args['show_image'],
'image_size' => $args['image_size'],
'plain_text' => $args['plain_text'],
'sent_to_admin' => $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
<?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 => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>">
<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;"><?php
// Show title/image etc
if ( $show_image ) {
echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->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;" /></div>', $item );
}
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
// SKU
if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
echo ' (#' . $_product->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->meta ) ) {
echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
}
// File URLs
if ( $show_download_links ) {
$order->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 );
?></td>
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ); ?></td>
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo $order->get_formatted_line_subtotal( $item ); ?></td>
</tr>
<?php
}
if ( $show_purchase_note && is_object( $_product ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?></td>
</tr>
<?php endif; ?>
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()
<em>PS: How can I see what is inside
Code:
$this->object
Code:
$this