Advertisement
nshelper

Untitled

Jul 3rd, 2023 (edited)
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.87 KB | None | 0 0
  1. if( sizeof( $items ) > 0 ) {
  2.             foreach ( $items as $item_id => $item ) {
  3.                
  4.               do_action( 'woocommerce/cart_loop/start', $item );
  5.                
  6.                 // Array with data for the pdf template
  7.                 $data = array();
  8.  
  9.                 // Set the item_id
  10.                 $data['item_id'] = $item_id;
  11.                
  12.                 // Set the id
  13.                 $data['product_id'] = $item['product_id'];
  14.                 $data['variation_id'] = $item['variation_id'];
  15.  
  16.                 // Compatibility: WooCommerce Composit Products uses a workaround for
  17.                 // setting the order before the item name filter, so we run this first
  18.                 if ( class_exists('WC_Composite_Products') ) {
  19.                     $order_item_class = apply_filters( 'woocommerce_order_item_class', '', $item, $this->order );
  20.                 }
  21.                
  22.                 // Set item name
  23.                 $data['name'] = apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
  24.                
  25.                 // Set item quantity
  26.                 $data['quantity'] = $item['qty'];
  27.  
  28.                 // Set the line total (=after discount)
  29.                 $data['line_total'] = $this->format_price( $item['line_total'] );
  30.                 $data['single_line_total'] = $this->format_price( $item['line_total'] / max( 1, abs( $item['qty'] ) ) );
  31.                 $data['line_tax'] = $this->format_price( $item['line_tax'] );
  32.                 $data['single_line_tax'] = $this->format_price( $item['line_tax'] / max( 1, abs( $item['qty'] ) ) );
  33.                
  34.                 $data['tax_rates'] = $this->get_tax_rate( $item, $this->order, false );
  35.                 $data['calculated_tax_rates'] = $this->get_tax_rate( $item, $this->order, true );
  36.                
  37.                 // Set the line subtotal (=before discount)
  38.                 $data['line_subtotal'] = $this->format_price( $item['line_subtotal'] );
  39.                 $data['line_subtotal_tax'] = $this->format_price( $item['line_subtotal_tax'] );
  40.                 $data['ex_price'] = $this->get_formatted_item_price( $item, 'total', 'excl' );
  41.                 $data['price'] = $this->get_formatted_item_price( $item, 'total' );
  42.                 $data['order_price'] = $this->order->get_formatted_line_subtotal( $item ); // formatted according to WC settings
  43.  
  44.                 // Calculate the single price with the same rules as the formatted line subtotal (!)
  45.                 // = before discount
  46.                 $data['ex_single_price'] = $this->get_formatted_item_price( $item, 'single', 'excl' );
  47.                 $data['single_price'] = $this->get_formatted_item_price( $item, 'single' );
  48.  
  49.                 // Pass complete item array
  50.                 $data['item'] = $item;
  51.                
  52.                 // Get the product to add more info
  53.                 if ( is_callable( array( $item, 'get_product' ) ) ) { // WC4.4+
  54.                     $product = $item->get_product();
  55.                 } elseif ( defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '4.4', '<' ) ) {
  56.                     $product = $this->order->get_product_from_item( $item );
  57.                 } else {
  58.                     $product = null;
  59.                 }
  60.                
  61.                 // Checking fo existance, thanks to MDesigner0
  62.                 if( !empty( $product ) ) {
  63.                     // Thumbnail (full img tag)
  64.                     $data['thumbnail'] = $this->get_thumbnail( $product );
  65.  
  66.                     // Set item SKU
  67.                     $data['sku'] = is_callable( array( $product, 'get_sku' ) ) ? $product->get_sku() : '';
  68.    
  69.                     // Set item weight
  70.                     $data['weight'] = is_callable( array( $product, 'get_weight' ) ) ? $product->get_weight() : '';
  71.                    
  72.                     // Set item dimensions
  73.                     if ( function_exists( 'wc_format_dimensions' ) && is_callable( array( $product, 'get_dimensions' ) ) ) {
  74.                         $data['dimensions'] = wc_format_dimensions( $product->get_dimensions( false ) );
  75.                     } else {
  76.                         $data['dimensions'] = '';
  77.                     }
  78.                                    
  79.                     // Pass complete product object
  80.                     $data['product'] = $product;
  81.                
  82.                 } else {
  83.                     $data['product'] = null;
  84.                 }
  85.                
  86.                 // Set item meta
  87.                 $data['meta'] = wc_display_item_meta( $item, apply_filters( 'wpo_wcpdf_display_item_meta_args', array( 'echo' => false ), $this ) );
  88.  
  89.                 $data_list[$item_id] = apply_filters( 'wpo_wcpdf_order_item_data', $data, $this->order, $this->get_type() );
  90.                
  91.                do_action( 'woocommerce/cart_loop/end', $item );
  92.             }
  93.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement