admin管理员组

文章数量:1122846

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!

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!

Share Improve this question edited Nov 24, 2018 at 4:08 butlerblog 5,0713 gold badges26 silver badges42 bronze badges asked Nov 6, 2018 at 17:16 SCormanSCorman 111 silver badge3 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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]'); 
}

本文标签: woocommerce offtopicReplace quotAdd to cartquot by a link to contact page on specific product