diff --git a/plugins/woocommerce-blocks/src/StoreApi/Schemas/V1/CartItemSchema.php b/plugins/woocommerce-blocks/src/StoreApi/Schemas/V1/CartItemSchema.php index 634210c506a..7d181a3db03 100644 --- a/plugins/woocommerce-blocks/src/StoreApi/Schemas/V1/CartItemSchema.php +++ b/plugins/woocommerce-blocks/src/StoreApi/Schemas/V1/CartItemSchema.php @@ -335,6 +335,20 @@ class CartItemSchema extends ProductSchema { public function get_item_response( $cart_item ) { $product = $cart_item['data']; + /** + * Filter the product permalink. + * + * This is a hook taken from the legacy cart/mini-cart templates that allows the permalink to be changed for a + * product. This is specific to the cart endpoint. + * + * @since 9.9.0 + * + * @param string $product_permalink Product permalink. + * @param array $cart_item Cart item array. + * @param string $cart_item_key Cart item key. + */ + $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $product->get_permalink(), $cart_item, $cart_item['key'] ); + return [ 'key' => $cart_item['key'], 'id' => $product->get_id(), @@ -348,7 +362,7 @@ class CartItemSchema extends ProductSchema { 'backorders_allowed' => (bool) $product->backorders_allowed(), 'show_backorder_badge' => (bool) $product->backorders_require_notification() && $product->is_on_backorder( $cart_item['quantity'] ), 'sold_individually' => $product->is_sold_individually(), - 'permalink' => $product->get_permalink(), + 'permalink' => $product_permalink, 'images' => $this->get_images( $product ), 'variation' => $this->format_variation_data( $cart_item['variation'], $product ), 'item_data' => $this->get_item_data( $cart_item ),