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!
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP