This was SOOO frustrating! I couldn’t find the documentation for this anywhere. I finally figured it out and so I wanted to share it with you.
This is if you want to replace the Add to cart button on the WooCommerce product archive page (shop page) with a normal button that links to the single product page for each product. The reason for this might be because potential customers have not yet seen the product page and you want them to visit that first.
Here’s the video…
Here’s the code…
/*PUT THIS IN YOUR CHILD THEME FUNCTIONS FILE*/ | |
/*STEP 1 - REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */ | |
function remove_loop_button(){ | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
} | |
add_action('init','remove_loop_button'); | |
/*STEP 2 -ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */ | |
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart'); | |
function replace_add_to_cart() { | |
global $product; | |
$link = $product->get_permalink(); | |
echo do_shortcode('<br>[button link="' . esc_attr($link) . '"]Read more[/button]'); | |
} | |
Leave a Reply to Umair Rasool Cancel reply