If you want to have 3 options instead of 2 for stock availability such as, "In Stock", "Out of Stock" and "On Hold", use the following code within the functions.php file://** Have 3 Options for Stock Availability: In Stock, Out of Stock, and On Hold **//
function add_custom_stock_type() {
?>
<script type="text/javascript">
jQuery(function(){
jQuery('._stock_status_field').not('.custom-stock-status').remove();
});
</script>
<?php
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'onhold' => __( 'On Hold', 'woocommerce' ), // The new option !!!
), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );}
add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');
function save_custom_stock_status( $product_id ) {
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
}
add_action('woocommerce_process_product_meta', 'save_custom_stock_status',99,1);
function woocommerce_get_custom_availability( $data, $product ) {
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $stock_status ) {
case 'onhold':
$data = array( 'availability' => __( 'On Hold', 'woocommerce' ), 'class' => 'on-hold' );
break;
case 'instock':
$data = array( 'availability' => __( 'Available Now', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Adopted', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
}
return $data;
}
add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 3, 2);
Search Knowledge Base Articles
Have 3 Options for Stock Availability in WooCommerce
Did you find this article useful?
Related Articles
-
Creating a New cPanel Account on WHM
Step 1: Log InLogin into the desired WHM accountStep 2: In WHM Dashboard Select "Create a New Account"Step 3: Domain InformationThe domain information... -
Privacy Policy Online Generator
Here is an online generator for a Privacy Policy:https://www.privacypolicygenerator.info/... -
Terms & Conditions Online Generator
Here's an online generator for "Terms & Conditions":https://www.termsandconditionsgenerator.com/You will have to spell-check because there are typ... -
WooCommerce Constant Loading on Credit Card Section
If after putting location in when checking out, and the credit card section keeps spinning, chances are you have to turn off and on the "mod_security2... -
Client not receiving emails from form on website.
The solution for this should be SPF record or if that doesn't work smtp issue. SPF record example: v=spf1 a mx ip4:xxx.xxx.xxx.xxx -allre...