0
votes

I am trying to change the redirect URL in the woocommerce for the 'add to cart' button in pages other than the single product page. The URL for the single product page can be changed with this solution. However this solution will not work for the for any other pages, to change the redirect after pressing the 'add to cart' button. Any help is greatly appreciated.

2

2 Answers

0
votes

To make woocommerce_add_to_cart_redirect work on pages like shop, categories or tags archives pages, you need first in backend WooCommerce > Settings > Products > Display:

enter image description here Disable the checkbox "Enable AJAX add to cart buttons on archives".

Then the hooked the code will work with woocommerce_add_to_cart_redirect hook on all woocommerce pages.

function wc_add_to_cart_custom_redirect() { 
    // Here the redirection
    return site_url('/mypage/'); 
}
add_filter( 'woocommerce_add_to_cart_redirect', 'wc_add_to_cart_custom_redirect' );
0
votes

You can use this in your Appearence>Theme Editor>function.php

add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product  ) {
    $button_text = __("View product", "woocommerce");
    $button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';

    return $button;
}

This will change your Add to cart to View porducts and the Url would be that specific products's Url