how to change add to cart become a social link

asyifa

Active member
Dec 10, 2018
470
122
43
hello, am i really confused how to change link add to cart in wordpress, i want change this but i dont know, where location this code, my bf say to me, impossible 😣
 

TassieNZ

Premium Uploader and Sometimes Hacker!
Jan 17, 2019
9,017
19,812
120
New Zealand
Do you mean the Add To Cart in WooCommerce? If so, it can be done. How are you with coding?

One of my clients needed to change the "Add to Cart" to "View Product". To do this we added the following PHP code at the bottom of the child theme functions.php. If you have no child theme, it goes in the themes functions.php, but you will need to add it again if your theme updates.

Not exactly what you want, but will give you an idea of the coding required.


PHP:
/**
 * @snippet       Remove Add Cart, Add View Product @ WooCommerce Loop
 * @add to child theme functions.php
 */
 
// First, remove Add to Cart Button
 
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
 
// Second, add View Product Button
 
add_action( 'woocommerce_after_shop_loop_item', 'view_product_button', 10);
 
function view_product_button() {
global $product;
$link = $product->get_permalink();
echo '<a href="' . $link . '" class="button addtocartbutton">View Product</a>';
}
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu