Advertisement
nshelper

WPGlobalCart - WooCommerce PayPal Payments

May 15th, 2024 (edited)
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1.     public function from_wc_cart( \WC_Cart $cart ): array {
  2.         $items = array_map(
  3.             function ( array $item ): Item {
  4.                
  5.                 do_action( 'woocommerce/cart_loop/start', $item );
  6.                
  7.                 $product       = $item['data'];
  8.                 $cart_item_key = $item['key'] ?? null;
  9.  
  10.                 /**
  11.                  * The WooCommerce product.
  12.                  *
  13.                  * @var \WC_Product $product
  14.                  */
  15.                 $quantity = (int) $item['quantity'];
  16.                 $image    = wp_get_attachment_image_src( (int) $product->get_image_id(), 'full' );
  17.                 $description = '';
  18.                 $price = (float) $item['line_subtotal'] / (float) $item['quantity'];
  19.                 return new Item(
  20.                     mb_substr( $product->get_name(), 0, 127 ),
  21.                     new Money( $price, $this->currency ),
  22.                     $quantity,
  23.                     $description,
  24.                     null,
  25.                     $this->prepare_sku( $product->get_sku() ),
  26.                     ( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
  27.                     $product->get_permalink(),
  28.                     $image[0] ?? '',
  29.                     0,
  30.                     $cart_item_key
  31.                 );
  32.                
  33.                 do_action( 'woocommerce/cart_loop/end', $item );
  34.             },
  35.             $cart->get_cart_contents()
  36.         );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement