修改woocommerce电子邮件中某些产品的数量

时间:2020-02-05 23:12:32

标签: php wordpress woocommerce

我需要这样做,以便订购电子邮件的数量仅对特定产品显示为两倍。我修改了email-order-items.php如下(不起作用):

添加到第28行:$product_id = $product->get_product_id(); 在第79行添加:

if( $product_id == 6960) {
    $qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty * 2 ) . '</ins>';
}

https://github.com/woocommerce/woocommerce/blob/master/templates/emails/email-order-items.php

1 个答案:

答案 0 :(得分:0)

您可以为此使用以下功能, 如果您不知道如何或在何处添加此代码,请查看以下链接

https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/

function filter_woocommerce_email_order_item_quantity( $qty_display, $item ) {
    $product = $item->get_product();
    $product_id = $product->get_id();

    if ( $product_id == 6960 ) {
        $qty_display = $qty_display * 2;
    }

    return $qty_display; 
}; 
add_filter( 'woocommerce_email_order_item_quantity', 'filter_woocommerce_email_order_item_quantity', 10, 2 );