diff --git a/includes/data/mutation/class-order-mutation.php b/includes/data/mutation/class-order-mutation.php index 53b89ceb..68c8b903 100644 --- a/includes/data/mutation/class-order-mutation.php +++ b/includes/data/mutation/class-order-mutation.php @@ -333,8 +333,10 @@ protected static function map_input_to_item( &$item, $input, $type ) { } } - // Calculate to subtotal/total for line items. - if ( isset( $args['quantity'] ) ) { + // If subtotal or total is not provided, calculate it based on the product price and quantity. + // If name is not provided, use the actual product name. + // ONLY IF $args is not empty. + if ( ! empty( $args ) && ( empty( $args['subtotal'] ) || empty( $args['total'] ) || empty( $args['name'] ) ) ) { $product = ( ! empty( $item['product_id'] ) ) ? wc_get_product( $item['product_id'] ) : wc_get_product( self::get_product_id( $args ) ); @@ -342,9 +344,10 @@ protected static function map_input_to_item( &$item, $input, $type ) { throw new \Exception( __( 'Failed to retrieve product connected to order item.', 'wp-graphql-woocommerce' ) ); } - $total = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ] ); + $total = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ?? 1 ] ); $args['subtotal'] = ! empty( $args['subtotal'] ) ? $args['subtotal'] : $total; $args['total'] = ! empty( $args['total'] ) ? $args['total'] : $total; + $args['name'] = ! empty( $args['name'] ) ? $args['name'] : $product->get_name(); } // Set item props.