skip to Main Content

Hi I want to change the “add to cart” button url on my single product page so when we click it , the button will redirect to another website (amazon).
Ps. im not a coder but simple code might work for me

2

Answers


  1. As Mentioned the description, you want to redirect to different page after the add to cart action.

    So, You can put the below code in functions.php file

    function redirect_after_add_to_cart( $url ) {
        return esc_url( get_permalink( get_page_by_title( 'Your Page Title' ) ) );
    }
    add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_after_add_to_cart', 99 );

    Thanks!!!

    Login or Signup to reply.
  2. Woocommerce works with a hook system, you can redirect the URL of your add to cart button with a php shortcode but, you can also use the plugin: Woocommerce Add to cart custom redirect. The best way for you if you don’t know how to use php shortcode 🙂

    link : https://fr.wordpress.org/plugins/woocommerce-add-to-cart-custom-redirect/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search