Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( sizeof( $items ) > 0 ) {
- foreach ( $items as $item_id => $item ) {
- do_action( 'woocommerce/cart_loop/start', $item );
- // Array with data for the pdf template
- $data = array();
- // Set the item_id
- $data['item_id'] = $item_id;
- // Set the id
- $data['product_id'] = $item['product_id'];
- $data['variation_id'] = $item['variation_id'];
- // Compatibility: WooCommerce Composit Products uses a workaround for
- // setting the order before the item name filter, so we run this first
- if ( class_exists('WC_Composite_Products') ) {
- $order_item_class = apply_filters( 'woocommerce_order_item_class', '', $item, $this->order );
- }
- // Set item name
- $data['name'] = apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
- // Set item quantity
- $data['quantity'] = $item['qty'];
- // Set the line total (=after discount)
- $data['line_total'] = $this->format_price( $item['line_total'] );
- $data['single_line_total'] = $this->format_price( $item['line_total'] / max( 1, abs( $item['qty'] ) ) );
- $data['line_tax'] = $this->format_price( $item['line_tax'] );
- $data['single_line_tax'] = $this->format_price( $item['line_tax'] / max( 1, abs( $item['qty'] ) ) );
- $data['tax_rates'] = $this->get_tax_rate( $item, $this->order, false );
- $data['calculated_tax_rates'] = $this->get_tax_rate( $item, $this->order, true );
- // Set the line subtotal (=before discount)
- $data['line_subtotal'] = $this->format_price( $item['line_subtotal'] );
- $data['line_subtotal_tax'] = $this->format_price( $item['line_subtotal_tax'] );
- $data['ex_price'] = $this->get_formatted_item_price( $item, 'total', 'excl' );
- $data['price'] = $this->get_formatted_item_price( $item, 'total' );
- $data['order_price'] = $this->order->get_formatted_line_subtotal( $item ); // formatted according to WC settings
- // Calculate the single price with the same rules as the formatted line subtotal (!)
- // = before discount
- $data['ex_single_price'] = $this->get_formatted_item_price( $item, 'single', 'excl' );
- $data['single_price'] = $this->get_formatted_item_price( $item, 'single' );
- // Pass complete item array
- $data['item'] = $item;
- // Get the product to add more info
- if ( is_callable( array( $item, 'get_product' ) ) ) { // WC4.4+
- $product = $item->get_product();
- } elseif ( defined( 'WOOCOMMERCE_VERSION' ) && version_compare( WOOCOMMERCE_VERSION, '4.4', '<' ) ) {
- $product = $this->order->get_product_from_item( $item );
- } else {
- $product = null;
- }
- // Checking fo existance, thanks to MDesigner0
- if( !empty( $product ) ) {
- // Thumbnail (full img tag)
- $data['thumbnail'] = $this->get_thumbnail( $product );
- // Set item SKU
- $data['sku'] = is_callable( array( $product, 'get_sku' ) ) ? $product->get_sku() : '';
- // Set item weight
- $data['weight'] = is_callable( array( $product, 'get_weight' ) ) ? $product->get_weight() : '';
- // Set item dimensions
- if ( function_exists( 'wc_format_dimensions' ) && is_callable( array( $product, 'get_dimensions' ) ) ) {
- $data['dimensions'] = wc_format_dimensions( $product->get_dimensions( false ) );
- } else {
- $data['dimensions'] = '';
- }
- // Pass complete product object
- $data['product'] = $product;
- } else {
- $data['product'] = null;
- }
- // Set item meta
- $data['meta'] = wc_display_item_meta( $item, apply_filters( 'wpo_wcpdf_display_item_meta_args', array( 'echo' => false ), $this ) );
- $data_list[$item_id] = apply_filters( 'wpo_wcpdf_order_item_data', $data, $this->order, $this->get_type() );
- do_action( 'woocommerce/cart_loop/end', $item );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement