ID : 0; // Reason for ignoring the rule: We are including this file on admin action in add_meta_box function callback. if ( ! $order_id && isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended $order_id = intval( wp_unslash( $_GET['id'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended } $order_obj = wc_get_order( $order_id ); $order_items = $order_obj->get_items( 'line_item' ); $shipping_fee = 0; $order_obj->calculate_totals(); foreach ( $order_items as $key => $value ) { $is_upsell = wc_get_order_item_meta( $key, '_cartflows_upsell', true ); $is_downsell = wc_get_order_item_meta( $key, '_cartflows_downsell', true ); $step_id = wc_get_order_item_meta( $key, '_cartflows_step_id', true ); $is_refunded = wc_get_order_item_meta( $key, '_cartflows_refunded', true ); if ( 'yes' == $is_upsell || 'yes' == $is_downsell ) { if ( 'yes' == $is_upsell ) { $offer_type = 'Upsell'; $transaction_id = wc_get_order_item_meta( $key, '_cartflows_offer_txn_id', true ); $shipping_fee = wc_get_order_item_meta( $key, '_cartflows_offer_shipping_fee', true ); } elseif ( 'yes' == $is_downsell ) { $offer_type = 'Downsell'; $transaction_id = wc_get_order_item_meta( $key, '_cartflows_offer_txn_id', true ); $shipping_fee = wc_get_order_item_meta( $key, '_cartflows_offer_shipping_fee', true ); } $products[ $key ] = array( 'order_id' => $value['order_id'], 'step_id' => $step_id, 'offer_type' => $offer_type, 'order_item_id' => $key, 'offer_product_id' => $value['product_id'], 'offer_product_name' => get_the_title( $value['product_id'] ), 'offer_product_total' => $value->get_total(), 'offer_product_qty' => $value->get_quantity(), 'offer_product_item_total' => 0, 'offer_product_item_tax' => 0, 'transaction_id' => $transaction_id, 'is_refunded' => 'yes' === $is_refunded ? true : false, 'shipping_fee' => $shipping_fee, ); if ( get_option( 'woocommerce_calc_taxes' ) ) { $products[ $key ]['offer_product_total'] = $products[ $key ]['offer_product_total'] + $value->get_total_tax(); $products[ $key ]['offer_product_item_total'] = $value->get_total(); $products[ $key ]['offer_product_item_tax'] = $products[ $key ]['offer_product_item_tax'] + $value->get_total_tax(); } if ( isset( $shipping_fee ) && ! empty( $shipping_fee ) && $shipping_fee > 0 ) { $products[ $key ]['offer_product_total'] = $products[ $key ]['offer_product_total'] + $shipping_fee; $products[ $key ]['offer_product_item_total'] = $value->get_total(); $products[ $key ]['offer_product_item_tax'] = $products[ $key ]['offer_product_item_tax'] + $shipping_fee; } } } // @codingStandardsIgnoreLine WordPress.Security.EscapeOutput.UnsafePrintingFunction ?>