lob0
lob0

Reputation: 317

Changing WooCommerce buy button link?

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 example.com

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.

Upvotes: 2

Views: 5792

Answers (3)

funkysoul
funkysoul

Reputation: 3241

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

<?php
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="//www.yourtargeturl.com?id='.$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;
}
?>

Upvotes: 1

Benoti
Benoti

Reputation: 2210

Depending on the product type you use. You can find all add_to_cart template file in the folder.

woocommerce/templates/single-product/add-to-cart/

You can set your product as external product, and it will redirect user to the external page.

If you want to stay with simple or variation product, you'll need to copy/paste the file you need in your child theme and modify it.

Upvotes: 0

Sumon Sarker
Sumon Sarker

Reputation: 2795

Woo-commerce plugin for Wordpress have custom add-to-cart features. You can add it from product or using shortcode to your script or posts.

Here is the details about -

Upvotes: 0

Related Questions