AI Verified

Name

Call Us / Add to Basket - Woo Button swap

About

Enable 'Add to Basket' for Products that are In Stock and 'Call Us' when items are out of stock

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Wanted the option to have 'Call Us' show for products out of stock, but 'Add to Basket' for products in stock. Created snippet using ChatGPT so not all my own work - but it appears to function all ok

Codevault

woldsnet_snippets

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

24/11/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Call Us / Add to Basket - Woo Button swap

 
                    
1function change_add_to_cart_text( $text, $product ) {
2 if ( ! $product->is_in_stock() ) {
3 $text = 'Call Us';
4 }
5 return $text;
6}
7add_filter( 'woocommerce_product_single_add_to_cart_text', 'change_add_to_cart_text', 10, 2 );
8add_filter( 'woocommerce_product_add_to_cart_text', 'change_add_to_cart_text', 10, 2 );

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Split Order

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

2

WooCommerce Change Add To Cart Button Text On Product Page

Added: 1 year ago

Last Updated: 2 months ago

Firstly, it’s important to note that if you’re trying to change the button text to either “add to cart” or “add to basket” then this guide is not for you. These two strings are default and based on yo...

WooCommerce

AI Verified

0

WooCommerce: Change the Order notes placeholder text.

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce checkout page. Change the placeholder text inside the Order notes field. https://easywebdesigntutorials.com/woocommerce-modifying-the-checkout-page/

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

Inventory Status Change

Added: 9 months ago

Last Updated: 9 months ago

I have a client who sells logs - has less than 10 products and doesn't use the stock management tools in WooCommerce. They wanted to control the Inventory on the basis of 'In Stock' or 'Out of Stock'...

WooCommerce

AI Verified

0

Call Us / Add to Basket - Woo Button swap

Added: 1 year ago

Last Updated: 9 months ago

Enable 'Add to Basket' for Products that are In Stock and 'Call Us' when items are out of stock