Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $orderItems = $order->get_items() + $order->get_items('fee');
- foreach ($orderItems as $itemId => $item) {
- do_action( 'woocommerce/cart_loop/start', $item );
- if ($onWoocommerceV3OrNewer) {
- $product = is_callable(array($item, 'get_product')) ? $item->get_product() : null;
- }
- else {
- $product = $order->get_product_from_item($item);
- }
- if ($includeOrdersWithOnlyVirtualItems) {
- $orderHasAtleastOneItem = true;
- }
- // skip items that don't require shipping
- else if ((!$product || !$product->needs_shipping()) && 'fee' !== $item['type']) {
- do_action( 'woocommerce/cart_loop/end', $item );
- continue;
- }
- $orderHasAtleastOneItem = true;
- $webshipItem = array(
- 'lineId' => (string) $itemId,
- );
- if ('fee' === $item['type']) {
- $webshipItem = array_merge($webshipItem, array(
- 'title' => $onWoocommerceV3OrNewer ? $item->get_name() : $item['name'],
- 'quantity' => (string) 1,
- 'price' => $order->get_item_total($item, false, true)
- ));
- }
- if ($product && $product->needs_shipping()) {
- $imageId = $product->get_image_id();
- $imgUrl = $imageId ? current(wp_get_attachment_image_src($imageId, 'shop_thumbnail')) : '';
- if (method_exists($product, 'get_id')) {
- $productId = $product->get_id();
- }
- else {
- $productId = $product->id;
- }
- $webshipItem = array_merge($webshipItem, array(
- 'productId' => (string) $productId,
- 'sku' => $product->get_sku(),
- 'title' => $product->get_title(),
- 'imgUrl' => $imgUrl,
- 'shippingWeight' => (string) wc_get_weight($product->get_weight(), 'lbs'),
- 'quantity' => (string) $item['qty'],
- 'price' => $order->get_item_subtotal($item, false, true),
- 'productLength' => $product->get_length(),
- 'productWidth' => $product->get_width(),
- 'productHeight' => $product->get_height(),
- 'url' => $product->get_permalink()
- ));
- }
- if ($item['item_meta']) {
- if (version_compare(WC_VERSION, '3.0.0', '<')) {
- $itemMeta = new WC_Order_Item_Meta($item, $product);
- $formattedMeta = $itemMeta->get_formatted('_');
- }
- else {
- add_filter('woocommerce_is_attribute_in_product_name', '__return_false');
- $formattedMeta = $item->get_formatted_meta_data();
- }
- if (!empty($formattedMeta)) {
- $attributes = array();
- foreach ($formattedMeta as $metaKey => $meta) {
- if (version_compare(WC_VERSION, '3.0.0', '<')) {
- array_push($attributes, array(
- 'name' => $meta['label'],
- 'value' => $meta['value']
- ));
- }
- else {
- array_push($attributes, array(
- 'name' => $meta->display_key,
- 'value' => wp_strip_all_tags($meta->display_value)
- ));
- }
- }
- $webshipItem['attributes'] = $attributes;
- }
- }
- array_push($webshipOrder['items'], $webshipItem);
- do_action( 'woocommerce/cart_loop/end', $item );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement