Commit 0bb0d2a573c for woocommerce

commit 0bb0d2a573c6558875f1e4173e8894e95b8fa4d2
Author: Albert Juhé Lluveras <contact@albertjuhe.com>
Date:   Mon Aug 10 13:21:37 2026 +0200

    Update product image SKU match checks (#67523)

    * Update product image SKU match checks

    * Add changelog

diff --git a/plugins/woocommerce/changelog/fix-WOO6-68 b/plugins/woocommerce/changelog/fix-WOO6-68
new file mode 100644
index 00000000000..94a299e3969
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-WOO6-68
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Update product image SKU match checks
diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php
index 393a980227e..362a94b4d5b 100644
--- a/plugins/woocommerce/includes/wc-product-functions.php
+++ b/plugins/woocommerce/includes/wc-product-functions.php
@@ -2261,7 +2261,7 @@ function wc_product_attach_featured_image( $attachment_id, $product = null, $sav
 		$product    = wc_get_product( $product_id );
 	}

-	if ( ! $product ) {
+	if ( ! $product || ! current_user_can( 'edit_product', $product->get_id() ) ) {
 		return;
 	}

diff --git a/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php
index 2174a058654..ec214e71f34 100644
--- a/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-product-functions-test.php
@@ -1456,4 +1456,45 @@ class WC_Product_Functions_Tests extends \WC_Unit_Test_Case {

 		return implode( "\n", (array) $before_data );
 	}
+
+	/**
+	 * @testdox Does not attach a featured image via SKU match when the current user cannot edit the product.
+	 */
+	public function test_wc_product_attach_featured_image_requires_edit_product_capability(): void {
+		update_option( 'woocommerce_product_match_featured_image_by_sku', 'yes' );
+
+		$sku     = 'TEST-SKU-ATTACH-' . wp_generate_password( 8, false );
+		$product = WC_Helper_Product::create_simple_product();
+		$product->set_sku( $sku );
+		$product->set_image_id( '' );
+		$product->save();
+
+		$attachment_id = wp_insert_attachment(
+			array(
+				'post_title'     => $sku,
+				'post_status'    => 'inherit',
+				'post_mime_type' => 'image/jpeg',
+			)
+		);
+
+		$subscriber_id = self::factory()->user->create( array( 'role' => 'author' ) );
+
+		try {
+			wp_set_current_user( $subscriber_id );
+
+			wc_product_attach_featured_image( $attachment_id );
+
+			$product = wc_get_product( $product->get_id() );
+			$this->assertEmpty(
+				$product->get_image_id(),
+				'Featured image should not be attached when the user lacks edit_product capability'
+			);
+		} finally {
+			wp_set_current_user( 0 );
+			wp_delete_attachment( $attachment_id, true );
+			WC_Helper_Product::delete_product( $product->get_id() );
+			wp_delete_user( $subscriber_id );
+			delete_option( 'woocommerce_product_match_featured_image_by_sku' );
+		}
+	}
 }