2016-04-30 20 views
0

私はwoocommerceの注文明細の詳細テンプレートのテーブルに作成したフィールドを表示しようとすると何か問題があります、そして、私はPHPにあまり知識がありません。セッションと呼ばれるフィールドを作成し、製品の投稿タイプとして登録しました。woocommerceオーダー明細の詳細テンプレートにカスタムフィールドを表示する方法は?

enter image description here

enter image description here

ユーザー一度にも表示されるように、私はカスタムフィールドをする製品(セッション)を購入。

ここでは、woocommerceのビューオーダーのテンプレートがあります。

<?php 
/** 
* Order Item Details 
* 
* This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.php. 
* 
*/ 

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

if (! apply_filters('woocommerce_order_item_visible', true, $item)) { 
    return; 
} 
?> 
<tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order)); ?>"> 
    <td class="product-name"> 

     <?php 
      $is_visible = $product && $product->is_visible(); 

      echo apply_filters('woocommerce_order_item_name', $is_visible ? sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']) : $item['name'], $item, $is_visible); 
      echo apply_filters('woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf('&times; %s', $item['qty']) . '</strong>', $item); 

      do_action('woocommerce_order_item_meta_start', $item_id, $item, $order); 

      $order->display_item_meta($item); 
      $order->display_item_downloads($item); 

      do_action('woocommerce_order_item_meta_end', $item_id, $item, $order); 
     ?> 
    </td> 
    <td class="product-total"> 
     <?php echo $order->get_formatted_line_subtotal($item); ?> 
    </td> 
</tr> 
<?php if ($show_purchase_note && $purchase_note) : ?> 
<tr class="product-purchase-note"> 
    <td colspan="3"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); ?></td> 
</tr> 
<?php endif; ?> 

私は

+0

編集テンプレートファイル 'WP-コンテンツ\テーマ\ - THEMENAME - \ woocommerce \チェックアウトを\ form-checkout.php'を開き、そこにフィールドをエコーし​​ます。あなたはacfを使っていますか? –

+0

はい私はACF – clestcruz

+0

を使用していますが、[get_field](https://www.advancedcustomfields.com/resources/get_field/) '$ field = get_field(" sessions "、idofproduct);' –

答えて

0

はこのアプローチを試してみて、あなたが得るものを見るレジに表示するthe_field(sessions)を挿入するは考えたり理解していません。また

<?php 
     /** 
     * Order Item Details 
     * 
     * This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.php. 
     * 
     */ 

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

     if (! apply_filters('woocommerce_order_item_visible', true, $item)) { 
      return; 
     } 
     $sessions = "sessions";  //DEFINE THE SESSIONS STRING... 
    ?> 
    <tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order)); ?>"> 
     <td class="product-name"> 

      <?php 
       $is_visible = $product && $product->is_visible(); 

       echo apply_filters('woocommerce_order_item_name', $is_visible ? sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']) : $item['name'], $item, $is_visible); 
       echo apply_filters('woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf('&times; %s', $item['qty']) . '</strong>', $item); 

       do_action('woocommerce_order_item_meta_start', $item_id, $item, $order); 

       $order->display_item_meta($item); 
       $order->display_item_downloads($item); 

       do_action('woocommerce_order_item_meta_end', $item_id, $item, $order); 

       //PERHAPS RIGHT HERE ADD THE SESSION 
       // IT IS IMPORTANT TO PASS IN THE PRODUCT-ID: $item['product_id'] SO THAT THE CORRECT FIELD IS RETRIEVED. 
       echo "<p class='session'><strong>" .__("Session: ", "ttd") . "</strong><em class='session-value'>" . get_field($sessions, $item['product_id']) . "</em></p>"; 
       //OR THIS WAY 
       echo "<p class='session'><strong>" .__("Session: ", "ttd") . "</strong><em class='session-value'>" . get_post_meta($item['product_id'], $sessions, true) . "</em></p>"; 
      ?> 
     </td> 
     <td class="product-total"> 
      <?php echo $order->get_formatted_line_subtotal($item); ?> 
     </td> 
    </tr> 
    <?php if ($show_purchase_note && $purchase_note) : ?> 
     <tr class="product-purchase-note"> 
      <td colspan="3"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); ?></td> 
     </tr> 
    <?php endif; ?> 

を、あなたも行うことができますそれはそうです:

<?php 
     /** 
     * Order Item Details 
     * 
     * This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.php. 
     * 
     */ 

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

     if (! apply_filters('woocommerce_order_item_visible', true, $item)) { 
      return; 
     } 
     $sessions = "sessions";  //DEFINE THE SESSIONS STRING... 
    ?> 
    <tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'order_item', $item, $order)); ?>"> 
     <td class="product-name"> 

      <?php 
       $is_visible = $product && $product->is_visible(); 

       echo apply_filters('woocommerce_order_item_name', $is_visible ? sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']) : $item['name'], $item, $is_visible); 
       echo apply_filters('woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf('&times; %s', $item['qty']) . '</strong>', $item); 

       do_action('woocommerce_order_item_meta_start', $item_id, $item, $order); 

       $order->display_item_meta($item); 
       $order->display_item_downloads($item); 

       do_action('woocommerce_order_item_meta_end', $item_id, $item, $order); 
      ?> 
     </td> 
     <td class="product-session"> 
      <!-- ALTERNATIVELY ADD THE SESSION RIGHT HERE ON A UNIQUE COLUMN--> 
      <!-- IT IS IMPORTANT TO PASS IN THE PRODUCT-ID: $item['product_id'] SO THAT THE CORRECT FIELD IS RETRIEVED.--> 
      <p class='session'> 
       <strong><?php echo __("Session: ", "ttd"); ?></strong> 
       <em class='session-value'><?php the_field($sessions, $item['product_id']); ?></em> 
      </p> 
      <!-- OR THIS WAY --> 
      <p class='session'> 
       <strong><?php echo __("Session: ", "ttd"); ?></strong> 
       <em class='session-value'><?php echo get_post_meta($item['product_id'], $sessions, true); ?></em> 
      </p> 
     </td> 
     <td class="product-total"> 
      <?php echo $order->get_formatted_line_subtotal($item); ?> 
     </td> 
    </tr> 
    <?php if ($show_purchase_note && $purchase_note) : ?> 
     <tr class="product-purchase-note"> 
      <td colspan="3"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); ?></td> 
     </tr> 
    <?php endif; ?> 

しかし、ファイル/テンプレート/注文/注文詳細.php。 35を介してライン1を選択し、その上に以下のコードを貼り付けます。このことができます

<?php 
/** 
* Order details 
* 
* This template can be overridden by copying it to yourtheme/woocommerce/order/order-details.php. 
* 
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer). 
* will need to copy the new files to your theme to maintain compatibility. We try to do this. 
* as little as possible, but it does happen. When this occurs the version of the template file will. 
* be bumped and the readme will list any important changes. 
* 
* @see   http://docs.woothemes.com/document/template-structure/ 
* @author WooThemes 
* @package WooCommerce/Templates 
* @version 2.5.3 
*/ 

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

$order = wc_get_order($order_id); 

$show_purchase_note = $order->has_status(apply_filters('woocommerce_purchase_note_order_statuses', array('completed', 'processing'))); 
$show_customer_details = is_user_logged_in() && $order->get_user_id() === get_current_user_id(); 
?> 
<h2><?php _e('Order Details', 'woocommerce'); ?></h2> 
<table class="shop_table order_details"> 
    <thead> 
    <tr> 
     <th class="product-name"><?php _e('Product', 'woocommerce'); ?></th> 
     <th class="product-session"><?php _e('Session', 'your_ttd'); ?></th> <!-- HERE WE ARE ADDING A COLUMN TO THE HEAD AS WELL TO MATCH...--> 
     <th class="product-total"><?php _e('Total', 'woocommerce'); ?></th> 
    </tr> 
    </thead> 
    <tbody> 

希望...

関連する問題