2017-12-20 8 views
1

電子メールを注文するカスタム注文メタを保存していますが、カスタムテンプレートでそれらのスタイルを設定する必要もあります。私がpタグにクラスを与えて、注文メタがラップされていても、クラスの配列がそのトリックをやっていないのが最も簡単です。WooCommerceの電子メール通知でカスタムメタデータにクラスを追加

function salesman_email_order_meta_fields($fields, $sent_to_admin, $order) { 
    $user_id = get_current_user_id(); 
    $key = 'billing_salesman'; 
    $single = true; 

    $current_user_has_discount = get_user_meta($user_id, $key, $single); 
    if(! empty($current_user_has_discount)){ 
    $fields['_billing_salesman'] = array(
     'label' => __('Sales Representative'), 
     'value' => $current_user_has_discount, 
     'class' => array('salesRep'), 
    ); 
    } 

    $is_po = get_post_meta($order->id, '_other_payment-admin-note', true); 
    if(! empty($is_po)){ 
     $fields['_other_payment-admin-note'] = array(
      'label' => __('PO Number'), 
      'value' => $is_po, 
      'class' => array('poNum'), 
     ); 
    } 

    return $fields; 
} 
add_filter('woocommerce_email_order_meta_fields', 'salesman_email_order_meta_fields', 11, 3); 

は、どのように私はカスタムオーダー電子メールのメタフィールドにクラスを追加、および/または電子メールテンプレートにそれらのスタイルを設定することができます?私が試した何

答えて

1

あなたは簡単にこのHTMLデータのスタイルを設定することができるようになります代わりにwoocommerce_email_after_order_tableアクションフックに引っかけカスタム関数、使用する必要があります。このコードは、あなたのアクティブな子テーマのfunction.phpファイルに行く

add_action('woocommerce_email_after_order_table', 'add_tracking_number_to_order_email', 10, 4); 
function add_tracking_number_to_order_email($order, $sent_to_admin, $plain_text, $email) 
{ 
    // (there is no current user ID for emails notifications) 
    $has_discount = get_user_meta($order->get_user_id(), 'billing_salesman', true); 
    $po_number = get_post_meta($order->get_id(), '_other_payment-admin-note', true); 

    if(empty($has_discount) && empty($po_number)) return; // Exit if empty 

    // CSS style 
    $styles = '<style> 
     table.salesman-meta{width: 100%; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif; 
      color: #737373; border: 1px solid #e4e4e4; margin-bottom:8px;} 
     table.salesman-meta th, table.tracking-info td{text-align: left; border-top-width: 4px; 
      color: #737373; border: 1px solid #e4e4e4; padding: 12px; width:50%;} 
     table.salesman-meta td{text-align: left; border-top-width: 4px; color: #737373; border: 1px solid #e4e4e4; padding: 12px; width:50%;} 
    </style>'; 

    // HTML Structure 
    $html_output = '<h2>'.__('Some title').'</h2> 
    <table class="salesman-meta" cellspacing="0" cellpadding="6">'; 

    if(! empty($has_discount)){ 
     $html_output .= '<tr class="sales-rep"> 
       <th>' . __('Sales Representative') . '</th> 
       <td>' . $has_discount . '</td> 
      </tr>'; 
    } 

    if(! empty($po_number)){ 
     $html_output .= '<tr class="po-num"> 
       <th>' . __('PO Number') . '</th> 
       <td>' . $po_number . '</td> 
      </tr>'; 
    } 

    $html_output .= '</table><br>'; // HTML (end) 

    // Output styles CSS + HTML 
    echo $styles . $html_output; 
} 

を(またはテーマ)または任意のプラグインファイルに保存されます。

テスト済みと(静的な値で)を作品 ...

+1

魔法のように動作しますが、再び一日を保存するためにありがとう! –

関連する問題