I would like to override the woocommerce_cart_item_name
hyperlink in order to direct the user to my own page when they click on the name of the product in the cart. I do not want to modify the woocommerce cart.php
or place a modified cart.php
in my child theme WooCommerce directory. I have tried adding the following to my functions.php
, but it does not work. My guess is that $_product->get_title()
does not work within the scope of functions.php
. What is the correct method that uses add_filter
to override the woocommerce_cart_item_name
? Thank you.
/* Function that returns custom product hyperlink */
function wc_cart_item_name_hyperlink() {
return sprintf( '<a href="%s">%s </a>','example.com/mypage/', $_product->get_title() );
}
/* Filter to override cart_item_name */
add_filter( 'woocommerce_cart_item_name', 'wc_cart_item_name_hyperlink' );