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 Then you can Easily Backup your previous 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. If you have any queries or any questions about this code snippets. Contact us for more information and follow us on LinkedIn, Facebook, and Instagram.