Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function from_wc_cart( \WC_Cart $cart ): array {
- $items = array_map(
- function ( array $item ): Item {
- do_action( 'woocommerce/cart_loop/start', $item );
- $product = $item['data'];
- $cart_item_key = $item['key'] ?? null;
- /**
- * The WooCommerce product.
- *
- * @var \WC_Product $product
- */
- $quantity = (int) $item['quantity'];
- $image = wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' );
- $description = '';
- $price = (float) $item['line_subtotal'] / (float) $item['quantity'];
- return new Item(
- mb_substr( $product->get_name(), 0, 127 ),
- new Money( $price, $this->currency ),
- $quantity,
- $description,
- null,
- $this->prepare_sku( $product->get_sku() ),
- ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
- $product->get_permalink(),
- $image[0] ?? '',
- 0,
- $cart_item_key
- );
- do_action( 'woocommerce/cart_loop/end', $item );
- },
- $cart->get_cart_contents()
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement