• Resolved oliver7772

    (@oliver7772)


    So This is the code I have:

    function phami_label_stock(){
    	global $product; 
    	$stock = ( $product->is_in_stock() )? 'in-stock' : 'out-stock' ; ?>
    	<div class="product-stock <?php echo esc_attr( $stock ); ?>">    
    		<span><?php esc_html_e( 'Availability:', 'phami' ); ?></span>
    		<i class="fa fa-check"></i><span class="stock"><?php  if( $product->is_in_stock() ){ echo esc_html__( 'In Stock', 'phami' ); }else{ echo esc_html__( 'Out of Stock', 'phami' ); } ?></span>
            <br>
            <span><?php esc_html_e( 'Lead Time:', 'phami' ); ?></span>
    		<i></i><span class="stock"><?php  if( $product->is_in_stock() ){ echo $product->get_stock_quantity().' '.esc_html__( 'Available for Immediate Dispatch', 'phami' ); }else{ echo esc_html__( 'Not Available - Contact Us For Further Information', 'phami' ); } ?></span>
    	</div>
    <?php }

    As seen, I have 2 things that are being displayed. Firstly whether it is in stock. Secondly. the leadtime and when it is avalivable. I would want to add another condition to these 2 statements. 1 for leadtime and one for stock.

    So this is my conditional for stock –

    1.) if Product is in stock – Should say “In stock”
    2.) if Product is out of stock – Should say “Out of stock”
    3.) if Product is back in order – Should say “Avaivable on back order!”

    This is my conditional for leadtime –

    1.) if Product is in stock – Should say “Avalivable for immideate dispatch.”
    2.) if Product is out of stock – Should say “Not Available – Contact Us For Further Information.”
    3.) if Product is back in order – Should say “should display 3-5 days delivery.”

    Thank you for your help. If you need anything else, let me know. ?? I appiriceate this amazing blog platform.

    I know this is big but i would appriceate if anyone would help me ??

    Regards,

    Oliver

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi

    Please try this one:

    add_filter( 'woocommerce_get_availability', 'ywp_custom_get_availability', 1, 2);
    function ywp_custom_get_availability( $availability, $_product ) {
    
        if ( $_product->backorders_allowed() ) {
            $availability['availability'] = 'should display 3-5 days delivery.';
    
            return $availability;
        }
    
        if ( $_product->is_in_stock() ) {
            $availability['availability'] = 'Avalivable for immideate dispatch.';
        } else {
            $availability['availability'] = 'Not Available – Contact Us For Further Information.';
        }
    
        return $availability;
    }

    NOTE: Code goes in function.php file of your active child theme (active theme).

    Good luck.

    Thread Starter oliver7772

    (@oliver7772)

    Unfortunately it did not work. I did try and add the filter however it still displayed in stock.

    Would this work?

    function phami_label_stock(){
    	global $product; 
    	$stock = ( $product->is_in_stock() )? 'in-stock' : 'out-stock' ; ?>
    	<div class="product-stock <?php echo esc_attr( $stock ); ?>">    
    		<span><?php esc_html_e( 'Availability:', 'phami' ); ?></span>
    		<i class="fa fa-check"></i><span class="stock"><?php  if( $product->is_in_stock() ){ echo esc_html__( 'In Stock', 'phami' ); } elseif ( $_product->backorders_allowed() ) { echo esc_html__( 'Back in Order', 'phami' ); } else{ echo esc_html__( 'Out of Stock', 'phami' ); } ?></span>
    <?php }

    ???

    • This reply was modified 4 years, 5 months ago by oliver7772.
    Thread Starter oliver7772

    (@oliver7772)

    Wait!!! Sorry it did work!!! Thanks

    Well done!

    You’re welcome

    Thread Starter oliver7772

    (@oliver7772)

    Thank you again. It’s just one more thing. Please see the image in the link. I’ve uploaded it to lightshot.

    So i want the message to show at a specific location. I want the message to show up next to lead time

    https://prntscr.com/sz8bcy

    Thank you again,

    Take care ??

    • This reply was modified 4 years, 5 months ago by oliver7772.
    Thread Starter oliver7772

    (@oliver7772)

    And also it still says in stock even though its in back in order?!

    So when its in back order, I want to display “back in order”, instead of “in stock”

    According to my code, the texts will be as follows and you can change them:

    Back in order: should display 3-5 days delivery.
    In stock: Avalivable for immideate dispatch.
    Out of stock: Not Available – Contact Us For Further Information.

    Unfortunately, I have no idea how to change the location of this message

    Plugin Support Tseten a11n

    (@tibetanitech)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How do I add back on order to my woocommerce single product template?’ is closed to new replies.