The key is to pass arguments to the callback function.
Try this:
/* Function that returns custom product hyperlink */
function wc_cart_item_name_hyperlink( $link_text, $product_data ) {
$title = get_the_title($product_data['product_id']);
return sprintf( '<a href="https://wordpress.stackexchange.com/questions/216353/%s">%s </a>','example.com/mypage/',$title );
}
/* Filter to override cart_item_name */
add_filter( 'woocommerce_cart_item_name', 'wc_cart_item_name_hyperlink', 10, 2 );
The $product_data
parameter is an array that contains the product_id
, variation_id
, quantity
, line_total
, line_tax
, line_subtotal
, line_subtotal_tax
, line_tax_data
, as well as an inner array called variation
that has more details.
Also, $product_data['data']
is the WC_Product_Simple object, which give you even more to work with.
Related Posts:
- wc_get_template_part( ‘content’, ‘product’ ) | Where is this file located?
- how to get woocommerce product attribute slug
- Is it safe to delete from db orphaned posts i.e. whose post_parent no longer exists?
- WooCommerce – Hook after Loading Variation in Admin Edit page?
- WooCommerce conditional meta query
- Add a custom button with custom link after add to cart for every product
- Redirect woocommerce single-product page
- Remove action on product archive page [closed]
- WooCommerce showing star rating review instead of text review string
- Username field is not shown in Woocommerce’s registration contact form
- Woocommerce Membership Expiry Date
- Get WooCommerce product attribute taxonomies in a SQL query on WordPress database
- Show all author products from specific category
- Sort orders by custom order meta – Woocommerce Orders admin page
- Redirect user to cart page when add to cart button is clicked
- Woo API REST : product variation price is read-only?
- how i can add more required * fields in checkout page?
- Disable Local Attributes woo commerce
- How to upload images from wordpress front-end (the first image must be thumbnail and the rest without first must be in gallery woocommerce product)
- Problems with varibel price [closed]
- Custom Admin Email Subject for Woocommerce (3.8.0) Orders
- Woocommerce custom endpoints
- Replacing products on Woocommerce Product Category with Search Results from SearchWP [closed]
- Creating custom permalink tags for WooCommerce
- Add Custom Slug Tags Per Page
- How to override Woocommerce functionality in Reports section?
- how can use woocommerce add to cart popup?
- wc_get_products() not return the images details
- Adding Product Name on Admin Panel Order list and User’s My-Account Order List
- How to put Stripe first, PayPal second on the checkout page?
- How to change product thumbnail size in storefront theme
- Override static method in WC_Shortcodes class (shortcode) [closed]
- Show add to cart button and quantity field when no price is entered [closed]
- Search in 1) Post, 2) Products (woocommerce) and 3) Custom post type or Taxonomy type on a single page
- Woocommerce REST API – add filter to set maximum query per page for product brands [closed]
- display product’s category static slider name and image in loop wordpress
- Whitespace between product image and gallery on initial load of lightbox product page
- Why is my WordPress login credentials missing, but work with WooCommerce?
- Update Customer JWT Woocommerce
- Is there a hook in woocommerce for when a payment fails to display a custom error message?
- How to reverse/swap the order of “Sales price” and “Regular prcie” in woocommerce?
- Woocommerce Canceled Order Notification email to admin
- separate functions for home VS other pages
- WooCommerce apply shipping rates based on price
- Extra items added to cart on refresh, woocommerce
- Woocommerce before and after shop loop not works
- WooCommerce Admin order – Only run action if user is loaded
- Creating child theme out of Coeur
- Hide sidebar and change layout Blog Page using is_page() function
- Change Out of Stock Error Message in WooCommerce Cart
- Woocommerce purchase date [closed]
- How to add a special Woocommerce “buy now” button?
- Woocommerce: Any way to list all products *without* a specific attribute?
- I want a simple dropdown for locations in woocommerce
- Getting hundreds of spam orders in WooCommerce with failed stripe payment [closed]
- How to fetch woocommerce highest price and lowest price in custom template page?
- Filter by Price filter button not working
- WooCommerce pagination: remove ‘page’ from url
- Coupon for product / woocommerce
- How can I show “sold out” instead of “out of stock” for some products with particular tags and categories [closed]
- How Can I fix Woocommerce Billing Address Field? [closed]
- Assign user role by text field in WordPress (Woocommerce) [closed]
- Urgent Validate Save-Post Hooks on Woo-commerce product entry form!
- Is doing a database query in Woocommerce efficient to only display posts from a certain category?
- Call product search from custom hook
- MySQL error or data corruption after database migration
- My products are showing “not in stock” and I don’t know why
- Woocommerce change the price of products in the database
- Select all products that have a custom field ‘is_new’ set to ‘Yes’
- Woocommerce – Shop can’t find products after domain name change
- “error_message”: “Sorry, you cannot list resources.” using WooCommerce API
- WooCommerce product details page category display
- Woocommerce – Default product image by user role
- add_post_meta on subcription renewal
- login or register then access woocommerce website
- Move woocommerce shop page image to left
- WooCommerce Tax Filter Not Working
- WooCommerce does not translate every string
- Woocommerce add a text field if specific option is selected
- Add suffix to price html does not work
- Get user active posts randomly
- Woocommerce Product category base same as product base causes 404
- Categories and products in cart Woocommerce
- SyntaxError: unterminated string literal – if WordPress Debug in wp-config is set to true
- How Fragile Is DB if I Upload Completely Updated Files
- Broken 302 redirection for product subcategory (Woocommerce, Apache)
- How to allow registration only from a certain location?
- Add confirmation popup on place order button
- Custom CSS Not working on Product page
- Change WooCommerce Checkout Button – Reverts to normal
- Can’t display product categories on woocommerce getting Invalid taxonomy?
- Send form data to functions.php
- How to remove content from hacked pages? [closed]
- Create custom add to cart in WordPress
- registration_errors not working
- Translate Woocommerce tab
- Woocommerce -> gallery images per variation without a plugin? [closed]
- Why is my WordPress admin not working
- Create bookings after subscription renewal
- Hook for Woocommerce checkout fields