How to Replace Out Of Stock with Contact Us page WooCommerce?

If a customer comes to your shop and finds products are running out of stock. He or she will definitely move to some other shop. This can result in loosing that customer forever. While we are sitting in world of internet where getting audience is a huge problem we cannot afford to lose even a single customer.

So we would be teaching you how you can save many of your customers by just adding a contact us page option instead of showing that you are running out of stock for a certain product. So with that being said let’s get started.

Our team at Themelocation is comprised of WordPress developers of high expertise

  • We can maintain, support and manage your single, or all your clients, website with dedication
  • Our skills are at your disposal.

Book a Call

To change Out of Stock to Contact Us page you just have to follow the simple guide given below:

  •   Go to your Dashboard->Appearance -> Editor
  •  Click on theme functions (functions.php)
  •  Add the Code in the bottom of functions file (Remember to backup functions.php file)

[codesyntax lang=”php”]
add_action( ‘woocommerce_after_shop_loop_item’, ‘themelocation_change_outofstock_to_contact_us’, 1 );

// for shop page

function themelocation_change_outofstock_to_contact_us(){
global $product;
if(!$product->is_in_stock()){
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’);

//change the link to your contact us page
echo ‘<a href=”themelocation.com” style=”background-color:#FAFAFA; padding:5px 15px;”> Contact Us </a>’;
}}

// for single page
add_filter( ‘woocommerce_get_availability’, ‘wcs_custom_get_availability’, 1, 2);
function wcs_custom_get_availability( $availability, $_product ) {

// Change In Stock Text
if ( $_product->is_in_stock() ) {
$availability[‘availability’] = __(‘Available!’, ‘woocommerce’);
}

// Change Out of Stock Text
if ( ! $_product->is_in_stock() ) {
$availability[‘availability’] = __(‘<a href=”themelocation.com” style=”background-color:#FAFAFA; padding:5px 15px;”> Contact Us </a>’, ‘woocommerce’);
}
return $availability;
}
[/codesyntax]

After adding this code whenever you would be out of stock instead of showing out of stock it will show a contact us button.

This will help you stop many of your customers from saying goodbye to your products.

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

Your email address will not be published. Required fields are marked *