1

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!

2
  • 1
    Welcome to WPSE, SCorman. If you found different snippets that you've tried but do not work, you might want to include what you've tried in your question, or at least expand on this so that people know what you've tried. Maybe someone might know why they don't work anymore and can suggest how to change it.
    – butlerblog
    Commented Nov 24, 2018 at 0:29
  • what do you mean by : on specific product page . by category , by tags, by product type ? ......
    – Younes.D
    Commented Jul 21, 2020 at 21:31

1 Answer 1

0

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]'); 
}
1
  • 1
    That won't work if he just wants it to happen on a specific product though, that'll change it everywhere. Commented Mar 15, 2020 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.