How To Change All “Buy” Button Urls To The One

I have an affiliate site with about 800 products, my existing affiliate is dead and I want to redirect all the traffic to another.

The easiest was I see now is to change all “BUY” button urls with the new affiliate link (to the homepage of my new affiliate program).

Read More

So, I need a solution to do this, does someone know the answer? thanks

Related posts

1 comment

  1. You need to modify the url via the woocommerce_product_add_to_cart_url filter in the add_to_cart_url() method of the product class.

    function so_30862586_add_to_cart_url( $url, $_product ) {
        if( $product->is_type( 'external' ) ) {
            $url = "http://www.stackoverflow.com";
        }
        return $url;
    }
    add_filter( 'woocommerce_product_add_to_cart_url', 'so_30862586_add_to_cart_url', 10, 2 );
    

Comments are closed.