WordPress.org

Forums

WooCommerce - excelling eCommerce
Automatically having products marked "Out of Stock" & Showing Stock Quantity (4 posts)

  1. Branmatt
    Member
    Posted 1 year ago #

    Hello everyone!

    I am currently trying to work out two issues I am having with WooCommerce.

    First, is there a way to have WooCommerce automatically mark a product as "Out of Stock" if the stock quantity is changed to 0? Right now I have a couple thousand products listed on my website. I update this list automatically everyday by using "CSV Import Suite", I choose to "Merge Products" and upload the updated CSV. Using this process, all of my products are updated daily with the current quantity of each product remaining. But, even though a product has "0" listed for its quantity the product is still shown as "In Stock"- is there any way via Settings or some Plugin to have WooCommerce recognize that this product is "Out of Stock" and mark it as such? And when the product has stock added to it again it will be marked as "In Stock"?

    This would be very difficult and time consuming to do manually.

    Secondly, while this is not a major issue, is there a way to display the remaining quantity of stock on the product's page? So instead of the product just being listed, it will show in the short description that there is: "X left in Stock". Is there any good way to do this?

    Thanks all for your help, and I look forward to hearing from you.
    I would be glad to clarify anything if necessary.

    Thanks again,
    -Brandon

    https://wordpress.org/plugins/woocommerce/

  2. terrytsang
    Member
    Posted 1 year ago #

    @Branmatt, you can paste this code to your theme functions.php:

    add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
    function custom_price_html( $price, $product ){
        global $post;
        $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
        if(is_single() && $sales_price_to != "")
        {
            $sales_price_date_to = date("j M y", $sales_price_to);
    
            return str_replace( '</ins>', ' </ins> <b>(Offer till '.$sales_price_date_to.')</b>', $price );
        }
        else
        {
            return apply_filters( 'woocommerce_get_price', $price );
        }
    }

    Hope it helps.

  3. terrytsang
    Member
    Posted 1 year ago #

    Hi @Branmatt, sorry, i posted the wrong code, above code will add sales end date for product page.

  4. Branmatt
    Member
    Posted 1 year ago #

    @terrytsang: So that code will not add either of the functions that I requested?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.