2016-11-02 13 views
0

私は、異なる(整数)値を持つ製品ごとに、WooCommerceのカスタムフィールドdays_manufactureを使用します。一部の電子メール通知でのみカスタム通知を表示

また、私は「製造日」の最高値と電子メール通知にメッセージを表示し、このコードを使用します。

add_action('woocommerce_email_before_order_table', 'days_of_manufacture_view_order_and_email', 99); 
    function days_of_manufacture_view_order_and_email($order, $type='email') { 
     $day_txt = ' ' . __('day', 'your_theme_domain_slug'); 
     $days_txt = ' ' . __('days', 'your_theme_domain_slug'); 
     $max_days = 0; 

     // Your customized style for the email template (to adapt for your needs) 
     $style = 'border:solid 2px #ededed; padding:10px; font-weight:bold;'; 

     // Your customized text goes in here 
     $text = __('Your Order will be produced in: ', 'your_theme_domain_slug'); 

     foreach($order->get_items() as $item) 
      if(get_post_meta($item['product_id'], 'days_manufacture', true) > $max_days) 
       $max_days = get_post_meta($item['product_id'], 'days_manufacture', true); 

     if($max_days != 0) { 
      if ($max_days == 1) 
       $days_txt = $day_txt; 

      $output = $text . $max_days . $days_txt; 

      // displayed on the email notifications 
      if($type == 'email') 
       echo "<div class='woocommerce-info' style='$style'>$output</div>"; // <== Customize the styles if needed 
      // displayed on the woocommerce templates 
      else 
       echo "<div class='woocommerce-info' style='display:block !important;'>$output</div>"; // displayed on the templates 
     } 
    } 

このコードは素晴らしい作品が、今、私はこれを表示したいと思いますメッセージは、「新規注文」、「注文処理」、「注文保留」および「失敗した注文」の電子メールにのみ含まれます。

どうすればこの問題を解決できますか?

おかげ

答えて

1

は、このカスタムメッセージを表示するためにのみ、特定の電子メール通知をターゲットにするための状態に基づいて条件を使用することが可能です。ここで

があなたの変更コードです:

add_action('woocommerce_email_before_order_table', 'days_of_manufacture_view_order_and_email', 99); 

function days_of_manufacture_view_order_and_email($order, $type='email') { 

    // Defining the undesired orders status 
    $not_this_statuses = array('wc-completed','wc-failed','wc-cancelled'); 
    if(!in_array($order->post_status, $not_this_statuses)){ 

     $day_txt = ' ' . __('day', 'your_theme_domain_slug'); 
     $days_txt = ' ' . __('days', 'your_theme_domain_slug'); 
     $max_days = 0; 

     // Your customized style for the email template (to adapt for your needs) 
     $style = 'border:solid 2px #ededed; padding:10px; font-weight:bold;'; 

     // Your customized text goes in here 
     $text = __('Your Order will be produced in: ', 'your_theme_domain_slug'); 

     foreach($order->get_items() as $item) 
      if(get_post_meta($item['product_id'], 'days_manufacture', true) > $max_days) 
       $max_days = get_post_meta($item['product_id'], 'days_manufacture', true); 

     if($max_days != 0) { 
      if ($max_days == 1) 
       $days_txt = $day_txt; 

      $output = $text . $max_days . $days_txt; 

      // displayed on the email notifications 
      if($type == 'email') 
       echo "<div class='woocommerce-info' style='$style'>$output</div>"; // <== Customize the styles if needed 
      // displayed on the woocommerce templates 
      else 
       echo "<div class='woocommerce-info' style='display:block !important;'>$output</div>"; // displayed on the templates 
     } 

    } 

} 

コードは、任意のプラグインファイルでも、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルになりますか。

これはテスト済みであり、動作します。

関連する問題