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 1 hour, 43 minutes ago by
Luke Nielsen.