• Resolved dyh1066

    (@dyh1066)


    Upon selection of a product variation I would expect the stock level for that specific variation to show but instead it shows the total across all 3 variations. It will correctly identify a stock level of zero and display OUT OF STOCK but the customer is still misled to believe there is more stock of a particular course (virtual product for in-person courses) than actually exists. The stock level for each of the 3 variations on this particular product is set to 10, zero and 8.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    I understand your concern. I tried replicating the issue on my site, but everything seems to be working fine on my end.

    To assist you better, could you please share a screenshot showing where you have set the stock quantity? If you don’t already have a screenshot service installed, you can use the following tool https://snipboard.io

    Additionally, could you run a conflict test to see if the issue is resolved? Here’s how:

    1. Create a staging site.
    2. Deactivate all plugins except WooCommerce.
    3. Activate a default WordPress theme, like Storefront or Twenty Twenty-Four.
    4. Check if the issue persists.

    For more details on how to run a conflict test, you can refer to this article: https://woocommerce.com/document/how-to-test-for-conflicts/.

    If you still face the same issue even after deactivating all plugins, I’d like to understand your site properly. Please share with us the necessary information below for us to investigate the issue further:

    • System Status Report?which you can find via WooCommerce > Status > Get system report > Copy for support.
    • Fatal error logs?(if any) under WooCommerce > Status > Logs.

    Once we have more information, we’ll be able to assist you further

    Thread Starter dyh1066

    (@dyh1066)

    Thanks for your reply. Disabling plugins resolved the issue and I was able to trace the source of the problem; namely the ‘search engine sourced’ code snippet (below) I’d added to swap the text “… in stock” to “… available places”. Clearly this code doesn’t work where there are variations:

    add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);

    function custom_get_availability( $availability, $_product ) {
    global $product;
    $stock = $product->get_total_stock();

    if ( $_product->is_in_stock() ) $availability[‘availability’] = ($stock . ‘ available places’, ‘woocommerce’); if ( !$_product->is_in_stock() ) $availability[‘availability’] = (‘SOLD OUT’, ‘woocommerce’);

    return $availability;

    Is there a tweak to this code to deliver the specific variation’s stock level, I wonder?

    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    Thanks for the update! I’m glad to hear that you were able to trace the source of the problem.

    Regarding the code, the issue arises because the code is referencing the total stock across all variations, rather than the stock of a specific variation. To target the stock of a particular variation, you’ll need to modify the code to work with the variation’s stock level.

    Please note that, generally, we do not provide support for customizations. However, I have found an article where you can get the code to change the text for product variations: https://puri.io/blog/change-stock-availability-text-woocommerce/

    If that does not help and you want to consider professional assistance for customization, I can recommend?WooExperts?and?Codeable.io?as options for getting professional help. Alternatively, you can also ask your development questions in the??WooCommerce Community Slack?as custom code falls outside our usual?scope of support.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.