net30 net30 - 1 year ago 142
HTML Question

Changing WooCommerce buy button link?

So I already have set up my WooCommerce child theme and organized the website with dummy data.

I can't find a way to change the link from the "Add to Cart" to an external link.
I want it so that each time someone clicks on the "Add to Cart" button the user be taken to external link

How do I go about this?

P.S: I'm not worried about any of the security aspects since the site won't be used for real money transactions.

Answer Source

not going to ask about the idea behind your question, but using this filter will for sure do what you need:

add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_product_link' );
function change_add_product_link( $link ) {
    global $product;
    $product_id = $product->id;
    $product_sku = $product->get_sku();
    $link = '<a href="//'.$product_id.'" rel="nofollow" data-product_id="'.$product_id.'" data-product_sku="'.$product_sku.'" data-quantity="1" class="button add_to_cart_button product_type_variable">'.sfws_woocommerce_product_add_to_cart_text().'</a>';
    return $link;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download