• Hi,

    I posted to WooThemes forum at the beginning of the week and had no response so thought I’d see if you guys and girls had any advice ??

    I need some help forming an IF and ELSE statement in my functions.php file.

    What I want to achieve is that if a product is out of stock and available for backorder, it will display a message such as available for pre order and the add to cart button on the single product page will also say pre order now.

    I then also want it to say if a product is marked as in stock to actually say available instead and the add to cart button text to remain the same.

    So far I have this;

    /**
    * WORKING EXAMPLE: CUSTOM: Changes Woocommerce Backorder Text on single product page
    */
    
    function woocommercecustomgetavailability( $availabilityinfo, $wcproduct ){
    if( $availabilityinfo['availability'] == 'Available on backorder' ){
    $availabilityinfo['availability'] = "Custom order - allow 2 weeks";
    }
    return $availabilityinfo;
    }
    addfilter( 'woocommercegetavailability', 'woocommercecustomgetavailability', 10, 2);
    addfilter( 'woocommerceproductaddtocarttext', 'wooarchivecustomcartbutton_text' ); // 2.1 +
    
    function wooarchivecustomcartbutton_text() {
    
        return __( 'Pre Order', 'woocommerce' );
    }

    But I can’t seem to get it to check the In Stock availability or change the add to cart text.

    I know the code is incomplete to achieve what I want but I can’t seem to figure it out (I am no coder)

    Can anybody please help?

    Many thanks

    https://www.ads-software.com/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    For a no-code solution, translate ‘Available on backorder’ with https://www.ads-software.com/plugins/say-what/

    Otherwise you need to target this core filter and run conditional checks in your own function:

    return apply_filters( 'woocommerce_get_availability', array( 'availability' => $availability, 'class' => $class ), $this );

    Thats from the product class.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom text depending on stock status’ is closed to new replies.