Skip to content

Commit

Permalink
Fixes in the receipts rendering engine (#47300)
Browse files Browse the repository at this point in the history
* Fix permission check in RestApiControllerBase

Extra arguments were being passed incorrectly to current_user_can,
causing wrong authentication failures in some cases (e.g.
when hitting the endpoints in a wp.com site via Jetpack tunneling).

* Fix get_order_data in ReceiptRenderingEngine

A fatal error was being thrown when one of the products referenced
in the order did no longer exist.
  • Loading branch information
Konamiman authored and senadir committed May 10, 2024
1 parent efac1cd commit 9085c31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/pr-47300
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixes regarding authentication and non-existing products in the receipts rendering engine
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,14 @@ private function get_order_data( WC_Order $order ): array {
$line_items = $order->get_items( 'line_item' );
foreach ( $line_items as $line_item ) {
$line_item_product = $line_item->get_product();
$line_item_title =
( $line_item_product instanceof \WC_Product_Variation ) ?
( wc_get_product( $line_item_product->get_parent_id() )->get_name() ) . '. ' . $line_item_product->get_attribute_summary() :
$line_item_product->get_name();
if ( false === $line_item_product ) {
$line_item_title = $line_item->get_name();
} else {
$line_item_title =
( $line_item_product instanceof \WC_Product_Variation ) ?
( wc_get_product( $line_item_product->get_parent_id() )->get_name() ) . '. ' . $line_item_product->get_attribute_summary() :
$line_item_product->get_name();
}
$line_items_info[] = array(
'type' => 'product',
'item' => $line_item,
Expand Down
2 changes: 1 addition & 1 deletion plugins/woocommerce/src/Internal/RestApiControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function internal_wp_error( Exception $exception ): WP_Error {
* @return bool|WP_Error True if the current user has the capability, otherwise an "Unauthorized" error or False if no error is available for the request method.
*/
protected function check_permission( WP_REST_Request $request, string $required_capability_name, ...$extra_args ) {
if ( current_user_can( $required_capability_name, $extra_args ) ) {
if ( current_user_can( $required_capability_name, ...$extra_args ) ) {
return true;
}

Expand Down

0 comments on commit 9085c31

Please sign in to comment.