尝试在Woocommerce中编辑订单详细信息页面

时间:2018-09-22 20:09:57

标签: mysql wordpress woocommerce

我正在使用Woocommerce在餐厅网站上工作。尝试以模式显示链接的产品。所以我有父产品和链接产品(子)。当用户单击父产品的购物车图标时,链接的/子产品会以模式显示。然后,用户可以从那里选择多个产品并添加到购物车。它几乎完美地工作。但是我想在订单详细信息页面(在admin中)和电子邮件(发票)中在相应的父产品下显示子产品。当前,子产品出现两次。作为母产品,再根据母产品。如您所见,带有绿色标记的产品是儿童。我不希望它们再次显示为红色。

这是前端:https://technovicinity.com/development/wordpress/mahmodul/bbeatery/our-menu/

谢谢所有专家。

enter image description here

下面是代码:

<div style="padding-left: 12px;width: 125%;padding-top: 20px;">
			<?php
			global $wpdb, $woocommerce;
			
			 $product_id =  $item->get_product_id(); 
            if($product_id ){ 
            $product = new WC_Product($product_id);
            $upsells = $product->get_upsell_ids();
            if(!empty( $upsells )){
            
            $args = array(
            'post_type' => 'product',
            'ignore_sticky_posts' => 1,
            'no_found_rows' => 1,
            'posts_per_page' => 30,
            'orderby' => 'name',
            'post__in' => $upsells,
            'post__not_in' => array($item_id), 
            );
            
            $product_upsells = new WP_Query($args);
            
            if ($product_upsells->have_posts()) :  
            $i=1;
            while ( $product_upsells->have_posts() ) : $product_upsells->the_post();   

            
			
		
             $child_name = get_the_title();
			$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE  order_item_name ='$child_name' AND order_id = '$order->id'", OBJECT );
			
			 
			foreach($results as $row){
			    $order_product_name = $row->order_item_name;  
			  
			  if($child_name == $order_product_name){ ?>
            
             <li>
			<?php
                 //print_r($post->ID);		
                $child_name = get_the_title(); 
                $_product = wc_get_product( $post->ID );
                $Price = $_product->get_price(); 			
                $currency_number = get_woocommerce_currency_symbol(); 
                echo $child_name;
			  ?>
             <span style="float:right;">			 
			 <?php  echo $currency_number.$Price. '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    X    &nbsp;&nbsp;&nbsp;1';   ?> 
             <span style="float:right">
			 <?php $total_order =  $Price * 1;   $total_order; ?>             
             </span> 
              <span style="float:right; padding-left:46px;">
			 <?php echo $currency_number.''.$total_order; ?>             
             </span>
             
             </li>
            
            <?php			
			/*echo "<br>";
			echo $post->ID;
			echo "<br>"; */ 
			?>
 
            <?php
			  }
			}
			 
            $i++;
            endwhile;
            endif; 
            
            wp_reset_postdata(); 
            
            } 
		   }
            ?>   
            </div>

0 个答案:

没有答案