TransWikia.com

Replace "Add to cart" by a link to contact page on specific product

WordPress Development Asked by SCorman on November 14, 2021

On my WooCommerce, I’m trying to hide “Add to cart” button and replace it by a “Contact us” button (with a link to contact page) on specific product page.

I’ve found different snippets but they don’t seem to work anymore :/

Any ideas? 🙂

Thank you very much!

One Answer

You can try this. I think it works fine.

/*PUT THIS IN YOUR THEME FUNCTIONS FILE*/

/*STEP 1 - REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */

add_action('init','remove_loop_button'); 
function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); 
}

/*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() {
    $link = get_permalink(get_page_by_path('contact-us')); //change 'contact-us' to your contact page slug.
    echo do_shortcode('<br>[button link="' . esc_attr($link) . '"]Contact us[/button]'); 
}

Answered by Quang Hoang on November 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP