4

在我的 WooCommerce 网站上,我使用Woocommerce 订单条码在电子邮件通知上显示订单条码。
我想隐藏或删除此条形码并已完成的订单状态电子邮件通知中显示它。

我试图编辑插件文件(我知道不推荐这样做)。我在class-woocommerce-order-barcodes.php插件文件中删除了这个(第 128 - 129 行):

// Add barcode to order complete email
add_action( 'woocommerce_email_after_order_table', array( $this, 'get_email_barcode' ), 1, 1 );

但它会从所有电子邮件通知中删除条形码。

如何从电子邮件通知中删除这些条形码并仅在完成的电子邮件通知中显示?

谢谢

4

1 回答 1

2

转而使其仅适用于已完成的订单状态电子邮件通知,就是在 IF 语句中添加这个小条件:

$order->has_status( 'completed' )

所以你可以先这样试试:

if (!$this->has_status( 'completed' ) ){
    add_action( 'woocommerce_email_after_order_table', array( $this, 'get_email_barcode' ), 1, 1 );
}

但由于我不确定在其中获取 $order 对象 ($this),因此我进一步查看了此插件的代码。

第 358 行,您可以在下面添加条件的代码。

/**
 * Get barcode for display in an email
 * @access  public
 * @since   1.0.0
 * @param   object $order Order object
 * @return  void
 */
public function get_email_barcode ( $order ) {

    if( ! $order ) return;

    // HERE is my condition  <====  <====  <====  <====  <====  <====  <====
    if (!$order->has_status( 'completed' ) ) return;

    // Generate correctly formatted HTML for email
    ob_start(); ?>

// … / …
// code of the function continues …

在这里,我很确定这会起作用,因为我们已经得到了$order对象。唯一的问题是,每次更新该插件时,您都必须再次添加此代码。

由于这是未经测试的,我不确定它是否会起作用。请给我一个反馈

于 2016-12-13T11:58:07.237 回答