From 3425a2c01784dcb9a812f60a1a512be38d6759a3 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Fri, 9 Aug 2024 17:52:32 +0200 Subject: [PATCH] Product Gallery: add defensive check (#50495) * Product Gallery: add defensive check * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: github-actions --- ...al-call-to-a-member-function-get_gallery_image_ids-on-bool | 4 ++++ .../BlockTypes/ProductGalleryLargeImageNextPrevious.php | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 plugins/woocommerce/changelog/50495-50460-fatal-call-to-a-member-function-get_gallery_image_ids-on-bool diff --git a/plugins/woocommerce/changelog/50495-50460-fatal-call-to-a-member-function-get_gallery_image_ids-on-bool b/plugins/woocommerce/changelog/50495-50460-fatal-call-to-a-member-function-get_gallery_image_ids-on-bool new file mode 100644 index 00000000000..4e3dfe3d3fd --- /dev/null +++ b/plugins/woocommerce/changelog/50495-50460-fatal-call-to-a-member-function-get_gallery_image_ids-on-bool @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak +Comment: Product Gallery: add defensive check to avoid fatal errors. + diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryLargeImageNextPrevious.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryLargeImageNextPrevious.php index 62421e313b4..2804ba23114 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryLargeImageNextPrevious.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryLargeImageNextPrevious.php @@ -74,6 +74,10 @@ class ProductGalleryLargeImageNextPrevious extends AbstractBlock { $product = wc_get_product( $post_id ); + if ( ! $product instanceof \WC_Product ) { + return ''; + } + $product_gallery = $product->get_gallery_image_ids(); if ( empty( $product_gallery ) ) {