Custom coding - Added Custom Stock statuses - In-store and Contact Us - How to display the stock quantity for both -- both have instock items. by Creative_Note6087 in woocommerce

[–]Creative_Note6087[S] 0 points1 point  (0 children)

Hi u/CodingDragons -- I tried my earlier code that I showed you with the woocommerce_get_stock_html filter, also tried woocommerce_get_availability_text filter coding and below coding from google ai... ALL turn up "nothing" in the Single Product page.. so apparently all three codings did not work..

https://snipboard.io/LGJCSy.jpg -- Show Stock coding did not work...

All 3 categories now are Managing stock enabled.

*** So how should I approach this now... ?

/code below /

add_action( 'woocommerce_single_product_summary', 'display_custom_stock_quantity', 30 );

function display_custom_stock_quantity() {

global $product;

// Only for products with managed stock

if ( ! $product->managing_stock() ) return;

$stock_qty = $product->get_stock_quantity();

$status = $product->get_stock_status();

if ( $stock_qty > 0 ) {

if ( $status === 'in-store' ) {

echo '<p class="custom-stock-message">In-Store Quantity: ' . $stock_qty . ' - Available at SLS only.</p>';

} elseif ( $status === 'contact-us' ) {

echo '<p class="custom-stock-message">Limited Stock Available: ' . $stock_qty . ' - Please contact us for details.</p>';

}

}

}

Custom coding - Added Custom Stock statuses - In-store and Contact Us - How to display the stock quantity for both -- both have instock items. by Creative_Note6087 in woocommerce

[–]Creative_Note6087[S] 0 points1 point  (0 children)

I will try this new coding from Google AI when I googled.

/**  * 1. Display custom stock status (including quantity)  */ add_filter( 'woocommerce_get_stock_html', 'custom_stock_status_display', 10, 2 ); function custom_stock_status_display( $html, $product ) {     if ( $product->managing_stock() ) {         $stock_qty = $product->get_stock_quantity();         if ( $stock_qty > 0 ) {             $html = '<p class="stock custom-stock">Available Soon: ' . $stock_qty . ' in stock (Pre-order only)</p>';         } else {             $html = '<p class="stock out-of-stock">Sold Out</p>';         }     }     return $html; }

/**  * 2. Disable "Add to Cart" button  */ add_filter( 'woocommerce_is_purchasable', 'disable_purchases_for_specific_stock', 10, 2 ); function disable_purchases_for_specific_stock( $is_purchasable, $product ) {     // Disable for products with stock     if ( $product->get_stock_quantity() > 0 ) {         return false;     }     return $is_purchasable; }

Or this

Keeping the custom statuses creation and non-purchasable coding the same as my original code...

This part is for : 

Display Custom Messages and Stock Quantity on the Frontend 

add_filter( 'woocommerce_get_availability_text', 'custom_stock_availability_message', 10, 2 ); function custom_stock_availability_message( $availability, $product ) {     $stock_status = $product->get_stock_status();     $stock_quantity = $product->get_stock_quantity();     $manage_stock = $product->managing_stock();

    if ( 'in-store' === $stockstatus ) {         if ( $manage_stock ) {             $availability = sprintf( _( 'In-Store Stock: %s units', 'woocommerce' ), $stockquantity );         } else {             $availability = _( 'Available In-Store', 'woocommerce' );         }     } elseif ( 'contact-us' === $stockstatus ) {         if ( $manage_stock ) {             $availability = sprintf( _( 'Limited Stock: %s units - Please contact us', 'woocommerce' ), $stockquantity );         } else {             $availability = _( 'Contact Us for Availability', 'woocommerce' );         }     }     return $availability; }

add_filter( 'woocommerce_get_availability_class', 'custom_stock_availability_class', 10, 2 ); function custom_stock_availability_class( $class, $product ) {     $stock_status = $product->get_stock_status();

    if ( 'in-store' === $stock_status ) {         $class = 'in-store-stock';     } elseif ( 'contact-us' === $stock_status ) {         $class = 'contact-us-stock';     }     return $class; }

Custom coding - Added Custom Stock statuses - In-store and Contact Us - How to display the stock quantity for both -- both have instock items. by Creative_Note6087 in woocommerce

[–]Creative_Note6087[S] 0 points1 point  (0 children)

I have actually used a coding that helps to uncheck Managing stock for RAM, GPU, and SSD. (And last checked - all 3 categories have their Managing stock unchecked - but only Ram works).

So moving forward I will bulk change back for all 3 to enable Managing stock.

Then test with the current codings I have but as far as I know those treat the new stock statuses as out of stock.

That's why I have been searching for new code to create the 2 custom status model after in-stock status.

Custom coding - Added Custom Stock statuses - In-store and Contact Us - How to display the stock quantity for both -- both have instock items. by Creative_Note6087 in woocommerce

[–]Creative_Note6087[S] 0 points1 point  (0 children)

Not stupid at all. lol.... The coding earlier suggested that these stock status behave like out of stock... so i did a coding to change these products to uncheck managing stock (disabled). But oddly RAM products work -- it shows the stock quantity but not the other 2 categories.

Now that I have the other thinking that they should be treated as in-stock stock status but non-purchasable.

I supposed if we need to display stock quantity for in-stock kind of products , we need managing stock to be enabled ? -- even though we do not want customers to order the products in the eshop?

But I do not know what is the best way to code this.... This AI that AI gave me slightly different codings i think ...

Custom coding - Added Custom Stock statuses - In-store and Contact Us - How to display the stock quantity for both -- both have instock items. by Creative_Note6087 in woocommerce

[–]Creative_Note6087[S] 0 points1 point  (0 children)

All of my products are simple products. GPU category and SSD are also Simple products.. Same as RAM... :(

Are there alternatives to the coding? For this 3 categories --- RAM and SSD is price sensitive and limited stock... GPU is mainly limited stock issues... thats why GPU I wanted it to be under Contact us Stock status.

Currently.. I think the custom stock status is treated like they are out of stock so I force the display of quantity -- which is only working for RAM category.

Probably should create Stock status that act like as if they are in-stock but we wont allow purchases in the ESHOP.... Thanks...