Schließen Sie die Rechnungsadresse aus bestimmten WooCommerce-E-Mail-Benachrichtigungen aus und zeigen Sie nur die Lieferadresse an
P粉071626364
P粉071626364 2023-12-29 14:46:55
0
1
475

Die Aktion „woocommerce_email_customer_details“ enthält Daten zur Rechnungsadresse und Lieferadresse. Ich benötige lediglich die Lieferadresse.

Wie kann ich dieses Ziel erreichen? Unten finden Sie meine aktuelle „Neue Bestellung“ E-Mail-Nur-Text-Vorlage (admin-new-order.php)

/*Admin new order email (plain text)*/
defined( 'ABSPATH' ) || exit;
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
if ( $additional_content ) {
    echo esc_html( wp_strip_all_tags( wptexturize( $additional_content ) ) );
}

P粉071626364
P粉071626364

Antworte allen(1)
P粉806834059

对于 HTML 电子邮件:

如果您使用此代码,它会从所需的电子邮件通知中删除帐单和送货信息。这是因为它确保相关的模板文件不被加载:

function action_woocommerce_email_customer_details( $order, $sent_to_admin, $plain_text, $email ) {
    $mailer = WC()->mailer();
    remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20 );
}
add_action( 'woocommerce_email_customer_details', 'action_woocommerce_email_customer_details', 5, 4 );

但是,由于您只想部分隐藏/不显示相关模板文件 (/emails/email-addresses.php) 的输出将需要一种不同的方法强>.

这可以通过根据您的需要调整/emails/email-addresses.php模板文件来完成。 可以通过将模板复制到来覆盖该模板 yourtheme/woocommerce/emails/email-addresses.php

注意:由于您只想将此应用于特定电子邮件通知,因此您需要使用 $email->id。由于默认情况下这不会传递到相关模板文件,因此需要解决方法

如果默认情况下不可用,如何将“$email”传递到 WooCommerce 电子邮件模板文件应答码中对此进行了描述.


所以回答你的问题:

步骤1)在活动子主题(或活动主题)的functions.php文件中添加

// Header - set global variable
function action_woocommerce_email_header( $email_heading, $email ) {
    $GLOBALS['email_id'] = $email->id;
} 
add_action( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 2 );

步骤 2)/emails/email-addresses.php 模板文件中,@version 5.6.0

替换第 18 - 20 行

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Getting the email ID global variable
$ref_name_globals_var = isset( $GLOBALS ) ? $GLOBALS : '';
$email_id = isset( $ref_name_globals_var['email_id'] ) ? $ref_name_globals_var['email_id'] : '';

替换第 28 - 40 行


    

get_billing_phone() ) : ?>
get_billing_phone() ); ?> get_billing_email() ) : ?>
get_billing_email() ); ?>


    
        

get_billing_phone() ) : ?>
get_billing_phone() ); ?> get_billing_email() ) : ?>
get_billing_email() ); ?>


对于纯文本电子邮件:

步骤1)在活动子主题(或活动主题)的functions.php文件中添加

function action_woocommerce_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
    // Plain text is TRUE and target specific email notification
    if ( $plain_text && $email->id == 'new_order' ) {
        $GLOBALS['email_id'] = $email->id;
    }
}
add_action( 'woocommerce_email_order_details', 'action_woocommerce_email_order_details', 1, 4 );

步骤 2)/emails/plain/email-addresses.php 模板文件中,@version 5.6.0

替换第 20 - 29 行

echo "\n" . esc_html( wc_strtoupper( esc_html__( 'Billing address', 'woocommerce' ) ) ) . "\n\n";
echo preg_replace( '#
#i', "\n", $order->get_formatted_billing_address() ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $order->get_billing_phone() ) { echo $order->get_billing_phone() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( $order->get_billing_email() ) { echo $order->get_billing_email() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped }

// Getting the email ID global variable
$ref_name_globals_var = isset( $GLOBALS ) ? $GLOBALS : '';
$email_id = isset( $ref_name_globals_var['email_id'] ) ? $ref_name_globals_var['email_id'] : '';

// Targeting NOT a specific email. Multiple statuses can be added, separated by a comma
if ( ! in_array( $email_id, array( 'new_order' ) ) ) {
    echo "\n" . esc_html( wc_strtoupper( esc_html__( 'Billing address', 'woocommerce' ) ) ) . "\n\n";
    echo preg_replace( '#
#i', "\n", $order->get_formatted_billing_address() ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $order->get_billing_phone() ) { echo $order->get_billing_phone() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( $order->get_billing_email() ) { echo $order->get_billing_email() . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } }
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!