mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Do not fail if no WC_Product in order item
It is possible for an order item to not have product, such as if created by a plugin.
This commit is contained in:
parent
77230fefa8
commit
4f91e78591
2 changed files with 13 additions and 18 deletions
|
@ -124,11 +124,6 @@ class ItemFactory {
|
|||
* @return Item
|
||||
*/
|
||||
private function from_wc_order_line_item( \WC_Order_Item_Product $item, \WC_Order $order ): Item {
|
||||
/**
|
||||
* The WooCommerce product.
|
||||
*
|
||||
* @var WC_Product $product
|
||||
*/
|
||||
$product = $item->get_product();
|
||||
$currency = $order->get_currency();
|
||||
$quantity = (int) $item->get_quantity();
|
||||
|
@ -139,13 +134,13 @@ class ItemFactory {
|
|||
$tax = new Money( $tax, $currency );
|
||||
|
||||
return new Item(
|
||||
mb_substr( $product->get_name(), 0, 127 ),
|
||||
mb_substr( $item->get_name(), 0, 127 ),
|
||||
new Money( $price_without_tax_rounded, $currency ),
|
||||
$quantity,
|
||||
substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ) ?: '',
|
||||
substr( wp_strip_all_tags( $product instanceof WC_Product ? $product->get_description() : '' ), 0, 127 ) ?: '',
|
||||
$tax,
|
||||
$product->get_sku(),
|
||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||
$product instanceof WC_Product ? $product->get_sku() : '',
|
||||
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue