Echoing the_permalink on a woocommerce product in the cart page will create a link with the attribute selection included in the link such as this:
http://ourdemo.com/product/product-test-2/?attribute_pa_frame=polished-chrome
We want to take these attributes out of the link (for various reasons), however it seems the_permalink, when run on the product id will return them automatically.
Looking at the documentation i cannot seem to find a parameter to not return the attributes? Is there another way to get the base permalink without any parameters?
Thanks
The trouble is that $_product->get_permalink($cart_item)
automatically adds the attributes to the permalink whenever the product in question is a variation.
I don't understand why you'd want to get rid of that behavior, but it can be accomplished by switching the $_product->get_permalink()
method to WordPress' default get_permalink()
function. For non-variation products, the method is just a "wrapper" anyway.
If you aren't showing thumbnails, then you can switch the title link via filter:
function so_remove_attributes_from_permalink( $name, $cart_item, $cart_item_key ){
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
if ( ! $_product->is_visible() ){
$name = sprintf( '<a href="%s">%s</a>', get_permalink( $cart_item['product_id'] ), $_product->get_title(), $cart_item, $cart_item_key );
}
return $name;
}
add_filter( 'woocommerce_cart_item_name', 'so_remove_attributes_from_permalink', 10, 3 );
If you are showing the thumbnails in the cart, then I think you will need to override the cart/cart.php
template and modify the references
$_product->get_permalink( $cart_item )
to
get_permalink( $cart_item['product_id'] )