banner



Change Read More Text in Woocommerce When Product Is Sold Out

If you're building a WooCommerce store, you'll know that out-of-the-box, the WooCommerce look and feel is okay merely not amazing. In a previous Divi tutorial, nosotros gave you lot a snippet that would bear witness you how to add an 'Add to Cart' button beneath your product listings. Today, we'll testify you lot how, with a picayune flake of PHP, y'all tin take this fifty-fifty farther to modify the WooCommerce Read More push button text to display as something custom.

When products are out of stock, the Add to Cart push button below the product showcase automatically displays with the text of 'Read More.' If you want to update this and see the WooCommerce Read More than button display every bit something else, all you'll need is a few lines of lawmaking.

In the following Divi tutorial, you lot'll get a short PHP snippet that volition allow yous alter the 'Read More than' text to whatsoever text you like.

Practice you desire to skip the step-by-footstep tutorial? Spring straight to the code library and add this PHP snippet to your functions.php file.

Customize WooCommerce: Change the Read More Button Text to Custom Text

By default, the WooCommerce Divi Shop module displays the text "Read More" when a product is out of stock. This isn't the near useful explanation for your store visitors who intend to buy goods or services.

Information technology would be far more helpful to display text that read something along the lines of :

  • Out of stock
  • Restocking soon
  • Add to wishlist
  • Add to waitlist

The last few options suggested above tin also nowadays great email listing building opportunities. Indicating that a production will be restocked soon can create urgency for your customers. Offer them an electronic mail sign upwardly for an alarm is great for not only collecting emails but as well edifice a strong relationship with your client.

Unfortunately, the default Read More than text can't be customized easily, so yous'll demand to be a fiddling crafty with code.

In this Divi tutorial, y'all'll get a quick snippet that'll help you sort out your online shop with a quick hack for WooCommerce of irresolute the Read More button text to something custom.

In this tutorial, you will:

  • Add a line of PHP to the functions.php file in your child theme.

If yous oasis't already set a child theme, we recommend installing and activating one to protect your piece of work. If you're non certain what a child theme is, read our guide on the topic. Y'all can also download a free Divi child theme from Divi Infinite.

Footstep one: Add a Divi Shop Module to a Layout

To begin, add a Divi Shop module to a page or post using the Divi Builder. Notation, this tutorial only works if yous've followed our previous snippet, of making the Add together to Cart push button display below product listings.

Divi Snippet WooCommerce Divi Shop module default

By default, out of stock products brandish with a Read More button

Past default, whatever product that is in stock will brandish every bit Add to Cart, just any products that are out of stock volition show a Read More button.

Step 2: Edit the functions.php File

Next, caput over to the Appearance > Theme Editor console and locate the functions.php file in your kid theme.

Copy and paste in the following code earlier the closing PHP ?> bracket:

add_filter( 'gettext', 'ds_change_readmore_text', 20, three );  function ds_change_readmore_text( $translated_text, $text, $domain ) { if ( ! is_admin() && $domain === 'woocommerce' && $translated_text === 'Read more') { $translated_text = 'Your custom text'; } return $translated_text; }

Divi Snippet Change WooCommerce Divi Shop module default Read More button

Add a few lines of PHP code to change the Read More push button to custom text

Any lawmaking added in between the brackets declared at $translated_text will begin to display. In the above example., the text Your custom text is set to display.

This produces the following event:

Divi Snippet WooCommerce Divi Shop module updated

View the updated button text

Do you lot see how the new out of stock production listing is reflecting equally the text entered into the PHP lawmaking?

Easy peasy!

Alternating Text Options

Y'all can play around an experiment with the button text past changing the declaration of $translated_text. In the following case, I've changed the text to reflect equally 'Add together to Wishlist'.

add_filter( 'gettext', 'ds_change_readmore_text', 20, 3 );  office ds_change_readmore_text( $translated_text, $text, $domain ) { if ( ! is_admin() && $domain === 'woocommerce' && $translated_text === 'Read more than') { $translated_text = 'Add to Wishlist'; } return $translated_text; }

Divi Snippet Change WooCommerce Divi Shop module default Read More button 2

Go crafty with the push button text, change it to anything you like!

Now, your customers volition know that they can still show their involvement in a product, even if it is out of stock.

Divi Snippet WooCommerce Divi Shop module updated 2

An alternate version of the Read More push button updated

With but a bit of PHP and CSS, y'all can better the user experience of your WooCommerce store and create a really engaging, lasting and memorable shopping experience for your customers.

If yous desire more code snippets, please post your snippet requests in the comment section below!

Change Read More Text in Woocommerce When Product Is Sold Out

Source: https://divi.space/wordpress-and-divi-code-snippets/woocommerce-change-read-more-button-text/

0 Response to "Change Read More Text in Woocommerce When Product Is Sold Out"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel