按顺序显示项目,包括图像WooCommerce



我正在尝试使用以下php显示WooCommerce订单中的产品/项目,但这些项目没有显示。

我使用的代码是对此的改编:获取购物车项目名称,数量所有详细信息 woocommerce。

使用上面问题的原始代码也不会在我的页面上显示任何内容。

提前谢谢。

<?php  

        global $woocommerce;
        $items = $woocommerce->cart->get_cart();
        foreach($items as $item => $values) { 
        $_product = $values['data']->post;
        //product image
        $getProductDetail = wc_get_product( $values['product_id'] );
        echo '<tr><td>';
        echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
        echo '</td>';
        echo '<td>';
        echo '<p style="font-size:10pt;">'.$_product->post_title.'</p><td><p style="font-size:10pt;">x'. $values['quantity'] . '</p></td>'; 
        echo '</td></tr>';
        };
   ?>

整页代码在这里:

<?php
/*
Template Name: Store
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');

?>
  <!DOCTYPE HTML>
  <html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>
      <?php _e('Store Queue'); ?>
    </title>
  </head>
  <body id="driverqueue">
    <header>
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <h1 class="title"><?php the_title(); ?></h1>
        <?php the_content(); ?>
          <?php endwhile; endif; ?>
    </header>
    <section>
      <?php 
  global $woocommerce;

  $args = array(
    'post_type' => 'shop_order',
    'post_status' => 'wc-processing',
    'meta_key' => '_customer_user',
    'posts_per_page' => '-1'
  );
  $my_query = new WP_Query($args);
  $customer_orders = $my_query->posts;
  foreach ($customer_orders as $customer_order) {
   $order = new WC_Order();
   $order->populate($customer_order);
   $orderdata = (array) $order;
   // $orderdata Array will have Information. for e.g Shippin firstname, Lastname, Address ... and MUCH more.... Just enjoy!
  }


  $loop = new WP_Query( $args );
  while ( $loop->have_posts() ) : $loop->the_post();

    $order_id = $loop->post->ID;
    $order = new WC_Order($order_id);
    ?>



        <table class="ordertable" id="<?php echo $order_id; ?>">
          <tr>
            <td>
              <p>Order #
                <?php echo $order_id; ?> &mdash;
                  <time datetime="<?php the_time('c'); ?>">
                    <?php echo the_time('d/m/Y g:i:s A'); ?>
                  </time>
              </p>
            </td>
            <td>
              <?php echo $order->billing_first_name . ' ' . $order->billing_last_name ?>
            </td>
            <td>
              <table>
                <tr>
                  <?php  

            global $woocommerce;
            $items = $woocommerce->cart->get_cart();
            foreach($items as $item => $values) { 
            $_product = $values['data']->post;
            //product image
            $getProductDetail = wc_get_product( $values['product_id'] );
            echo '<tr><td>';
            echo $getProductDetail->get_image(); // accepts 2 arguments ( size, attr )
            echo '</td>';
            echo '<td>';
            echo '<p style="font-size:10pt;">'.$_product->post_title.'</p><td><p style="font-size:10pt;">x'. $values['quantity'] . '</p></td>'; 
            echo '</td></tr>';
            };
              ?>
                </tr>
              </table>
            </td>
            <td>
              <p>
                <?php
            do_action( 'woocommerce_admin_order_actions_start', $order );
            $actions = array();

            if ( $order->has_status( array( 'pending', 'on-hold', 'processing' ) ) ) {
              $actions['complete'] = array(
                'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=awaiting-shipment&order_id=' . $post->ID ), 'woocommerce-mark-order-status' ),
                'name'      => __( 'Complete', 'woocommerce' ),
                'action'    => "complete"
              );
            };
            $actions = apply_filters( 'woocommerce_admin_order_actions', $actions, $order );
            foreach ( $actions as $action ) {
              printf( '<a class="button %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
            }
            do_action( 'woocommerce_admin_order_actions_end', $order );
          ?>
              </p>
            </td>
            <td>
              <form action="">
                <input type="checkbox" class="ordercollected" value="0" />
              </form>
            </td>
          </tr>
          <?php endwhile; ?>
    </section>
  </body>
  </html>

使用以下链接中的信息和以下改编的代码解决了这个问题:

https://wordpress.stackexchange.com/questions/180075/how-to-get-woocommerce-order-product-info

<?php  
foreach ($order->get_items() as $key => $lineItem) {
        //uncomment the following to see the full data
               // echo '<pre>';
               // print_r($lineItem);
               // echo '</pre>';
                $product_id = $lineItem['product_id'];
                $product = wc_get_product( $product_id );
                echo '<tr><td>' . $product->get_image() . '</td>'; // accepts 2 arguments ( size, attr )
                echo '<td>' . 'Product: ' . $lineItem['name'] . '</td>';
                echo '<td> x' . $lineItem['qty'] . '</td></tr>';
              }
              ?>

最新更新