Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add woocommerce_cart_item_permalink filter to cart item endpoint #8726

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/StoreApi/Schemas/V1/CartItemSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ public function get_properties() {
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(),
Expand All @@ -348,7 +362,7 @@ public function get_item_response( $cart_item ) {
'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 ),
Expand Down