• I’ve searched and searched and tried all the suggestions, such as this.

    The code below doesn’t work. It’s what’s always suggested. It changes the “out of stock” text in the item description area, but not on the actual badge that appears over the image. For the life of me, no matter what I try, I cannot change the text there. Where is that text stored? What file? Where? I’m happy to manually change it every time there’s an update if that’s what it takes.

    All help appreciated. Thanks. The theme I’m using is Shopisle, btw.

    This doesn’t work:

    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'] = __('Sold Out', 'woocommerce');
        }
        return $availability;
    }
Viewing 13 replies - 1 through 13 (of 13 total)
  • I’m not sure if you’re going to apply it to variable products so I’ll cover both.

    Add this to your child theme thru FTP. Do not edit or add to a parent theme.

    
    // For all products except variable product
    add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
    function wcs_custom_get_availability( $availability, $_product ) {
        
      // Change Out of Stock Text
        if ( ! $_product->is_in_stock() ) {
               $availability['availability'] = __('Sold Out', 'woocommerce');
        }
        return $availability;
    }
    
    // For each variation on a variable product)
    add_action( 'woocommerce_after_add_to_cart_button', 'after_add_to_cart_button_action_callback', 0 );
    function after_add_to_cart_button_action_callback() {
        global $product;
        if( $product->is_type('variable') ) :
            $data = [];
    
    // Loop through variation Ids
        foreach( $product->get_visible_children() as $variation_id ){
                 $variation = wc_get_product( $variation_id );
                 $data[$variation_id] = $variation->is_in_stock();
        }
    
        $outofstock_text = __("Sold Out", "woocommerce");
    ?>
       <script type="text/javascript">
        jQuery(function($){
            var b = 'button.single_add_to_cart_button',
                t = $(b).text();
    
            $('form.variations_form').on('show_variation hide_variation found_variation', function(){
                $.each(<?php echo json_encode($data); ?>, function(j, r){
                    var i = $('input[name="variation_id"]').val();
                    if(j == i && i != 0 && !r ) {
                        $(b).html('<?php echo $outofstock_text; ?>');
                        return false;
                    } else {
                        $(b).text('Add To Cart');
                    }
                });
            });
        });
        </script>
        <?php
        endif;
    }
    
    

    I’m using my phone so hopefully it parsed correctly.

    Thread Starter markisland

    (@markisland)

    Thank you, @serafinnyc ! Unfortunately, adding this to my child theme functions.php file, it still doesn’t affect the badge itself, which still reads “Out of Stock”. Could anything be overriding this?

    Hey @markisland !

    It sounds like you are trying to change some of the words from WooCommerce on your site. If you are comfortable with coding you are welcome to explore that route, but it is not something we can really help with.

    What we typically suggest for this situation is string translations. You can do this by using a free translation plugin like Loco Translate – https://wordpress.org/plugins/loco-translate/. I know it may sound strange to “translate” your own language, but it works. 🙂 This will allow you to find that phrase and change it to be what you’d like.

    Feel free to check out our guide for the exact steps.

    I hope this helps!

    What theme are you using and are you using any page builders like Elementor?

    Thread Starter markisland

    (@markisland)

    Hi @arcangelini ! Thank you. Believe it or not, I already tried this as I saw someone else solve this problem using Loco Translate. It did not work for me. I suspect something is blocking the change.

    Hi @arcangelini – I’m using ShopIsle by ThemeIsle. I don’t believe I’m using anything like Elementor, but where would I go to check? I can give you a list of things I’m using if you point me in the right direction, and then maybe you can let me know what might be blocking the change.

    Hey @markisland !

    Thanks for the details.

    If neither the code you shared or Loco translate are working then it does sound like something is interrupting this string replacement.

    Typically issues like this are caused by either a conflict with your theme or another plugin. How we usually address this type of issue is to have you temporarily switch back to the Storefront – https://woocommerce.com/products/storefront/ theme and disable all plugins except for WooCommerce (and the trouble plugin). You can do this manually from your WP-ADMIN ⇢ Plugin area, or by using a tool like [Health Check – https://wordpress.org/plugins/health-check/ . If that resolves the issue, then one-by-one you can switch back your theme and re-enable your plugins, testing in between, until you find the one causing the conflict.

    Health Check – https://wordpress.org/plugins/health-check/ is a tool that can be useful for debugging, though it requires an official default WordPress theme like Twenty Twenty – https://wordpress.org/themes/twentytwenty/. On the troubleshooting tab, you can click the button to disable all plugins and change the theme for you while you’re logged in to that session without affecting normal visitors to your site. For more details, see our Health Check doc.

    If you’ve tried the above with no success, then would you mind sharing a copy of your site’s System Status report?

    You can find it by going to WooCommerce ⇢ Status Select “Get system report” and then “Copy for support”. Once you’ve done that, you can paste it here in reply.

    Thanks!

    Thread Starter markisland

    (@markisland)

    Thank you, @arcangelini ! I did what you suggested and disabled all plugins. No such luck there. Then I attempted to active the default WooCommerce Storefront theme, and unfortunately that theme doesn’t even have the badge that I’m referring to ((example shown here on the ‘black dress’ thumbnail – “Sale!”).

    So, per your request, here’s the system report via WooCommerce:


    ### WordPress Environment ###

    WordPress address (URL): https://nickarcidy.com/store
    Site address (URL): https://nickarcidy.com/store
    WC Version: 4.1.1
    REST API Version: ✔ 1.0.7
    WC Blocks Version: ✔ 2.5.16
    Action Scheduler Version: ✔ 3.1.6
    WC Admin Version: ✔ 1.1.3
    Log Directory Writable: ✔
    WP Version: 5.4.1
    WP Multisite: –
    WP Memory Limit: 256 MB
    WP Debug Mode: –
    WP Cron: ✔
    Language: en_US
    External object cache: –

    ### Server Environment ###

    Server Info: Apache
    PHP Version: 7.3.18
    PHP Post Max Size: 260 MB
    PHP Time Limit: 30
    PHP Max Input Vars: 1000
    cURL Version: 7.70.0
    OpenSSL/1.1.1g

    SUHOSIN Installed: –
    MySQL Version: 5.6.41-84.1
    Max Upload Size: 256 MB
    Default Timezone is UTC: ✔
    fsockopen/cURL: ✔
    SoapClient: ✔
    DOMDocument: ✔
    GZip: ✔
    Multibyte String: ✔
    Remote Post: ✔
    Remote Get: ✔

    ### Database ###

    WC Database Version: 3.8.1
    WC Database Prefix: eef_
    Total Database Size: 3.02MB
    Database Data Size: 2.81MB
    Database Index Size: 0.21MB
    eef_woocommerce_sessions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_api_keys: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_order_items: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_order_itemmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_tax_rates: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_woocommerce_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_actionscheduler_actions: Data: 0.02MB + Index: 0.02MB + Engine MyISAM
    eef_actionscheduler_claims: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_actionscheduler_groups: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_actionscheduler_logs: Data: 0.01MB + Index: 0.01MB + Engine MyISAM
    eef_commentmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_comments: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_failed_jobs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_links: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_mailchimp_carts: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_mailchimp_jobs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_options: Data: 2.70MB + Index: 0.07MB + Engine MyISAM
    eef_postmeta: Data: 0.02MB + Index: 0.02MB + Engine MyISAM
    eef_posts: Data: 0.06MB + Index: 0.01MB + Engine MyISAM
    eef_queue: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_say_what_strings: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_termmeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_terms: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_term_relationships: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_term_taxonomy: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_usermeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_users: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_wc_admin_notes: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_admin_note_actions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_category_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_customer_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_download_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_order_coupon_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_order_product_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_order_stats: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_order_tax_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wc_product_meta_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_wc_tax_rate_classes: Data: 0.00MB + Index: 0.01MB + Engine MyISAM
    eef_wc_webhooks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM
    eef_wpforms_tasks_meta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM

    ### Post Type Counts ###

    attachment: 6
    custom_css: 1
    customize_changeset: 37
    nav_menu_item: 3
    page: 7
    post: 2
    product: 2
    revision: 6

    ### Security ###

    Secure connection (HTTPS): ✔
    Hide errors from visitors: ✔

    ### Active Plugins (1) ###

    WooCommerce: by Automattic – 4.1.1

    ### Inactive Plugins (12) ###

    Akismet Anti-Spam: by Automattic – 4.1.5
    Google Analytics for WordPress by MonsterInsights: by MonsterInsights – 7.10.4
    Jetpack by WordPress.com: by Automattic – 8.5
    Loco Translate: by Tim Whitlock – 2.4.0
    Mailchimp for WooCommerce: by Mailchimp – 2.4.0 – Installed version not tested with active version of WooCommerce 4.1.1
    MOJO Marketplace: by Mike Hansen – 1.5.3
    OptinMonster API: by OptinMonster Team – 1.9.7 – Installed version not tested with active version of WooCommerce 4.1.1
    Say What?: by Lee Willis – 1.9.4
    WooCommerce Admin: by WooCommerce – 1.1.3
    WooCommerce Services: by Automattic – 1.23.0 – Installed version not tested with active version of WooCommerce 4.1.1
    WooCommerce Stripe Gateway: by WooCommerce – 4.4.0 – Installed version not tested with active version of WooCommerce 4.1.1
    WPForms Lite: by WPForms – 1.6.0.2

    ### Dropin Plugins (2) ###

    db-error.php: db-error.php
    maintenance.php: maintenance.php

    ### Must Use Plugins (3) ###

    Endurance Browser Cache: by Mike Hansen – 0.4
    Endurance Page Cache: by Mike Hansen – 2.0
    SSO: by Garth Mortensen
    Mike Hansen – 0.3

    ### Settings ###

    API Enabled: –
    Force SSL: –
    Currency: USD ($)
    Currency Position: left
    Thousand Separator: ,
    Decimal Separator: .
    Number of Decimals: 2
    Taxonomies: Product Types: external (external)
    grouped (grouped)
    simple (simple)
    variable (variable)

    Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
    exclude-from-search (exclude-from-search)
    featured (featured)
    outofstock (outofstock)
    rated-1 (rated-1)
    rated-2 (rated-2)
    rated-3 (rated-3)
    rated-4 (rated-4)
    rated-5 (rated-5)

    Connected to WooCommerce.com: –

    ### WC Pages ###

    Shop base: #6 – /
    Cart: #7 – /cart/
    Checkout: #8 – /checkout/
    My account: #9 – /my-account/
    Terms and conditions: ❌ Page not set

    ### Theme ###

    Name: Shop Isle Child
    Version: 0.1
    Author URL:
    Child Theme: ✔
    Parent Theme Name: Shop Isle
    Parent Theme Version: 1.1.60
    Parent Theme Author URL: https://themeisle.com
    WooCommerce Support: ✔

    ### Templates ###

    Overrides: –

    ### Action Scheduler ###

    Complete: 57
    Oldest: 2020-05-25 02:31:46 +0000
    Newest: 2020-05-30 17:36:21 +0000

    Pending: 2
    Oldest: 2020-05-30 17:59:16 +0000
    Newest: 2020-05-30 17:59:16 +0000

    `

    Thank you!

    Thread Starter markisland

    (@markisland)

    Apologies, @serafinnyc , I responded to you previously but tagged the wrong person. Here’s my response to your earlier question:

    I’m using ShopIsle by ThemeIsle. I don’t believe I’m using anything like Elementor, but where would I go to check? I can give you a list of things I’m using if you point me in the right direction, and then maybe you can let me know what might be blocking the change.

    Since then, I’ve attempted disabling all plugins (per my post above) with no luck!

    No worries @markisland So the screenshot shows a “On Sale” badge and not an out of stock. So that’s probably why this isn’t working.

    If you want to show a custom badge instead I suggest using a plugin. There are several on Envato

    There are also some here. YITH makes a great one.

    And here’s an article on the 5 best.

    If you don’t want to go that route and you want to simply change the test of “Sale” you can try this code.

    
    add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
    function woocommerce_custom_sale_text($text, $post, $_product)
    {
        return '<span class="onsale">PUT YOUR TEXT</span>';
    }
    

    Tested and works.

    Thread Starter markisland

    (@markisland)

    @serafinnyc My apologies! Sorry to waste your time – yes, the image shows “On Sale” rather than “Out of Stock”, because that’s all I could find an example of on the theme’s website. Just wanted to show the badge component I was referring to. This same badge shows “Out of Stock” when that status is selected for a given item, and cannot be changed to anything else based on how I have things set up/what I’ve tried.

    And you for sure put the product to “out of stock”?

    Can you send me the page where the product is out of stock please?

    Thread Starter markisland

    (@markisland)

    Correct! Just sent you an email with the URL to the product to your ‘info@’ email address. Thank you!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Change “out of stock” text in badge to “sold”’ is closed to new replies.