Rumah  >  Soal Jawab  >  teks badan

Kecualikan alamat pengebilan daripada pemberitahuan e-mel WooCommerce tertentu, tunjukkan hanya alamat penghantaran

Tindakan "woocommerce_email_customer_details" mengandungi data alamat pengebilan dan alamat penghantaran. Apa yang saya perlukan ialah alamat penghantaran.

Bagaimana saya boleh mencapai matlamat ini? Di bawah ialah "Pesanan Baharu" templat teks biasa e-mel semasa saya (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粉071626364P粉071626364269 hari yang lalu417

membalas semua(1)saya akan balas

  • P粉806834059

    P粉8068340592023-12-30 10:19:53

    Untuk e-mel HTML:

    Jika anda menggunakan kod ini, ia akan mengalih keluar maklumat pengebilan dan penghantaran daripada pemberitahuan e-mel yang diperlukan. Ini kerana ia memastikan fail templat yang berkaitan tidak dimuatkan:

    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 );
    

    Walau bagaimanapun, memandangkan anda hanya mahu menyembunyikan sebahagian/tidak menunjukkan output fail templat yang berkaitan (/email/email-addresses.php) pendekatan berbeza akan diperlukan .

    Ini boleh dilakukan dengan menyesuaikan fail templat /email/email-addresses.php mengikut keperluan anda. Templat ini boleh diganti dengan menyalinnya yourtheme/woocommerce/emails/email-addresses.php

    Nota: Memandangkan anda hanya mahu menggunakan ini pada pemberitahuan e-mel tertentu, anda perlu menggunakan $email->id. Memandangkan ini tidak dihantar ke fail templat yang berkaitan secara lalai, penyelesaian diperlukan.

    Cara menghantar "$email" ke fail templat e-mel WooCommerce jika ia tidak tersedia secara lalai Ini diterangkan dalam kod respons.


    Jadi untuk menjawab soalan anda:

    Langkah 1)Tambah dalam fail functions.php

    tema kanak-kanak aktif (atau tema aktif)
    // 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 );
    

    Langkah 2) Dalam fail templat /email/email-addresses.php, @versi 5.6.0

    Ganti baris 18 - 20

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

    dan

    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'] : '';
    

    dan

    Ganti baris 28 - 40

    
        

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

    dan

    
        
            

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


    Untuk e-mel teks biasa:

    Langkah 1)Tambah dalam fail functions.php

    tema kanak-kanak aktif (atau tema aktif)
    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 );
    

    Langkah 2) Dalam fail templat /email/plain/email-addresses.php, @versi 5.6.0

    Ganti baris 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
    }
    

    dan

    // 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
        }
    }
    

    balas
    0
  • Batalbalas