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 3 posts - 1 through 3 (of 3 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 1 hour, 43 minutes ago by Luke Nielsen.
    #659183

    Madoo Webdesign
    Participant

    It works!

    Thank you very much

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