Home Forums WoodMart support forum Archive/product grid cart button redirect to single product page

Archive/product grid cart button redirect to single product page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #659114

    Madoo Webdesign
    Participant

    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

    #659169

    Luke Nielsen
    Keymaster

    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 4 hours, 46 minutes ago by Luke Nielsen.
    #659183

    Madoo Webdesign
    Participant

    It works!

    Thank you very much

    #659207

    Luke Nielsen
    Keymaster

    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

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Archive/product grid cart button redirect to single product page’ is closed to new replies.