Woo Commerce- Remove Add to cart button and put an Email Button with mail to link. - Ajiva Infotech

Latest

Thursday, January 30, 2020

Woo Commerce- Remove Add to cart button and put an Email Button with mail to link.


Here we are with another blog post related to Woo-commerce. in this, we can let you that how you can remove Add to cart button/link and put the Email button with mail link. as we see there are lots of people asking questions about it that how they can do this with a simple code of the snippet.
  • First of all, you need to remove the Add to cart button from your website.
  • Go to your active theme function.php file which is located in your website's active theme file.
  • Here's the code for the same through which you can remove your Add to cart button/link.
  • Please take the backup of your previous file in case you do something wrong while customizing the current code. 
  • Please implement below code for remove Add to cart button/link:-


// For remove Add to cart button
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart');

  • After you removed the Add to cart button/link from your website, now its time to put an email button with a link in there. 
  • For this, you need to put the below code in the same file from where you removed the Add to cart button code. Just place the below code and save the file. 
  • Here the code for add an email button with mail link:-


// add inquiry button into every product
add_action( 'woocommerce_after_shop_loop_item', 'prfx_add_inquiry_button', 10); // catalog page
add_action( 'woocommerce_single_product_summary', 'prfx_add_inquiry_button', 30); // single product page
function prfx_add_inquiry_button() {
    $current_product_id = get_the_ID(); // get ID of the current post
    $current_product_title = get_the_title(); // get the title of the current post
    $product = wc_get_product( $current_product_id ); // get the product object
    echo $current_product_title;
    echo '<a href="mailto:test@example.com?subject=Inquiry for product id:$current_product_id" class="button">Inquiry</a>';
    echo '</a>';
}



So that's it for now, Hope you guys like this. We will come up with another blog post soon. Contact us for more information and follow us on LinkedIn, Facebook and Instagram. Also, subscribe to email alerts.

Our New Apps Available on  Play store hope you like Download and share your suggestions: 

Success Quotes 

Screen recording app without watermark
Screen Recorder

3 comments: