Ajouter le nom du produit dans le sujet de la notification par e-mail de nouvelle commande WooCommerce
P粉990008428
P粉990008428 2023-08-18 08:55:45
0
1
659
<p>Je souhaite modifier la ligne d'objet de l'e-mail que j'envoie au propriétaire du magasin pour y inscrire le nom du produit. J'ai vu ce code pour mettre le nom du client devant Comment puis-je ajuster ce code pour inclure le nom du produit</p> <pre class="brush:php;toolbar:false;">/* * Placez-le dans le fichierfunctions.php ou le plug-in personnalisé du thème * * Filtre de sujets : *woocommerce_email_subject_new_order *woocommerce_email_subject_customer_processing_order *woocommerce_email_subject_customer_completed_order *woocommerce_email_subject_customer_invoice *woocommerce_email_subject_customer_note *woocommerce_email_subject_low_stock *woocommerce_email_subject_no_stock *woocommerce_email_subject_backorder *woocommerce_email_subject_customer_new_account *woocommerce_email_subject_customer_invoice_paid **/ add_filter('woocommerce_email_subject_new_order', 'change_admin_email_subject', 1, 2); function change_admin_email_subject( $subject, $order ) { $woocommerce mondial ; $nom du blog = wp_specialchars_decode(get_option('nom du blog'), ENT_QUOTES); $subject = sprintf( '[%s] Nouvelle commande client (# %s) du nom %s %s', $blogname, $order->id, $order->billing_first_name, $order->billing_last_name ) ; renvoyer $sujet ; }</pré> <p>Peut-être devons-nous simplement apporter des modifications ici</p> <pre class="brush:php;toolbar:false;">$subject = sprintf( '[%s] Nouvelle commande client (# %s) du nom %s %s', $blogname, $item-> ;get_name, $order->billing_first_name, $order->billing_last_name ); renvoyer $sujet ; }</pré> <p><br /></p>
P粉990008428
P粉990008428

répondre à tous(1)
P粉207483087

Votre code actuel est obsolète... Pour ajouter le nom du produit acheté (et la quantité) au sujet de la notification par e-mail de nouvelle commande envoyée à l'administrateur, utilisez le code suivant :

add_filter('woocommerce_email_subject_new_order', 'change_email_subject_new_order', 10, 2);
function change_email_subject_new_order( $formatted_subject, $order ) {
    $products = array(); // 初始化

    // 循环遍历订单项目
    foreach( $order->get_items() as $item ){
        // 将格式化的产品名称和数量添加到数组中
        $products[] = sprintf( '%s &times; %d', $item->get_name(), $item->get_quantity() );
    }

    $count    = count($products); // 产品数量
    $products = implode(', ', $products); // 将数组转换为字符串

    return sprintf( 
        __('[%s] 新客户订单(#%s),%s,来自%s%s', 'woocommerce'), 
        wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), $order->get_order_number(), 
        sprintf( _n('产品(%s)', '产品(%s)', $count, 'woocommerce'), $products, $products ),
        $order->get_billing_first_name(), $order->get_billing_last_name() 
    );
}

Placez le code dans le fichier function.php de votre thème enfant (ou dans un plugin). Il a été testé et fonctionne bien.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!