2017-04-22 16 views

答えて

1

まず私たちは、「新規注文」電子メール通知をターゲットに電子メールIDを取得する必要があります。唯一の方法は、前にそれを取得し、グローバル変数に値を設定することです。

woocommerce_order_item_meta_endアクションフックに引っ掛けられたカスタム機能では、新規注文の電子メール通知専用の製品説明が表示されます。ここで

はそのコードです:

## Tested on WooCommerce 2.6.x and 3.0+ 

// Setting the email_is as a global variable 
add_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4); 
function the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email){ 
    $GLOBALS['email_id_str'] = $email->id; 
} 

// Displaying product description in new email notifications 
add_action('woocommerce_order_item_meta_end', 'product_description_in_new_email_notification', 10, 3); 
function product_description_in_new_email_notification($item_id, $item, $order){ 

    // Getting the email ID global variable 
    $refNameGlobalsVar = $GLOBALS; 
    $email_id = $refNameGlobalsVar['email_id_str']; 

    // If empty email ID we exit 
    if(empty($email_id)) return; 

    // Only for "New Order email notification" 
    if ('new_order' == $email_id) { 

     // Get The product ID (for simple products) 
     $product_id = $item['product_id']; 

     // Get an instance of WC_Product object 
     $product = wc_get_product($product_id); 

     // Get the Product description (WC version compatibility) 
     if (method_exists($item['product'], 'get_description')) { 
      $product_description = $product->get_description(); // for WC 3.0+ (new) 
     } else { 
      $product_description = $product->post->post_content; // for WC 2.6.x or older 
     } 

     // Display the product description 
     echo '<div class="product-description"><p>' . $product_description . '</p></div>'; 
    } 
} 

このコードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルに入るか、また、どのプラグインファイルに。

このコードはテスト済みであり、動作します。

コードの更新とwoocommerce_order_item_meta_endアクションフックでのエラーの説明:

PHP Warning for woocommerce_order_item_meta_end (Mike Joley)

+0

返信いただきありがとうございます。それは働いている。私は今、製品の説明と電子メールを受信して​​います。ただし、注文後、このメッセージがページに表示されます: 警告:/home/cbllookbook/public_html/wp-content/themes/you-child/functions.php 22行目のproduct_description_in_new_email_notification()の引数4がありません function_description_in_new_email_notification($ item_id、$ item、$ order、$ plain_text){ 引数を並べ替えるべきですか?再度、感謝します。 –

+0

これを行う正しい方法であるかどうかはわかりません。しかし、引数4の値をNULLに設定して、メッセージを取り除くことができます。 –

関連する問題