Archive/product grid cart button redirect to single product page
-
Good afternoon, is there any possibility to redirect the shopping cart button on the archive page or from a product grid to the single product page instead of putting the product in the shopping cart?
I have now solved it with 2 buttons. View and in cart. But I only want 1 and that is the standard cart button that leads to the single product page instead of putting the product in the shopping cart
thank you in advance
Hello,
Try to use the code below to redirect to the single product on the Archive page:
add_filter('woocommerce_loop_add_to_cart_link', 'custom_redirect_add_to_cart_button', 10, 2);
function custom_redirect_add_to_cart_button($button, $product) {
// Only change simple products that are purchasable and in stock
if (
$product->is_type('simple') &&
$product->is_purchasable() &&
$product->is_in_stock()
) {
$url = get_permalink($product->get_id());
$label = esc_html__('Add to Cart', 'woocommerce');
return '<a href="' . esc_url($url) . '" class="button">' . $label . '</a>';
}
// Return the original button for all other product types
return $button;
}
Kind Regards
-
This reply was modified 3 months, 2 weeks ago by
Luke Nielsen.
It works!
Thank you very much
Hello,
Thank you for confirming that the solution works for your needs. Should you have any further questions or require additional assistance, feel free to reach out.
Kind regards
The topic ‘Archive/product grid cart button redirect to single product page’ is closed to new replies.