Woocommerce stock status in shop page and product page
up vote
0
down vote
favorite
Good day,
Im using this code, but stock status is still "In stock" and "Out of stock" but also must be "Preorder" and "On request".
Its happened after Wordpress Jupiter theme update, about few days looking for reason and solution. Can you please help?
/* add custom stock status */
function woocommerce_add_custom_stock_status()
?>
<script type="text/javascript">
jQuery(function()
jQuery('._stock_status_field').not('.custom-stock-status').remove();
);
</script>
<?php
/* update custom status if backorder if varations updated */
$real_stock_status = get_post_meta($_REQUEST['post'], '_stock_status', true );
if($real_stock_status=="onpreorder")
$stock_status = get_post_meta($_REQUEST['post'], '_custom_stock_status', true ); //get status from custom meta
update_post_meta($_REQUEST['post'], '_stock_status', wc_clean( $stock_status ));
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'onpreorder' => __( 'Preorder', 'woocommerce' ),
'onrequest' => __( 'On request', 'woocommerce' ),
'eof' => __( 'End of life', 'woocommerce' ),
), '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', 'woocommerce_add_custom_stock_status');
/* save custom stock status */
function woocommerce_save_custom_stock_status( $product_id )
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
update_post_meta( $product_id, '_custom_stock_status', wc_clean( $_POST['_stock_status'] ) ); //save another custom meta since '_stock_status' will be overridden
add_action('woocommerce_process_product_meta', 'woocommerce_save_custom_stock_status',99,1);
/* get custom stock status */
function get_custom_stock_status( $data, $product )
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $product->stock_status )
case 'instock':
$data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
case 'onpreorder':
$data = array( 'availability' => __( 'Preorder', 'woocommerce' ), 'class' => 'on-preorder' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'On request', 'woocommerce' ), 'class' => 'on-request' );
break;
case 'eof':
$data = array( 'availability' => __( 'End of life', 'woocommerce' ), 'class' => 'end-of-life' );
break;
return $data;
add_action('woocommerce_get_availability', 'get_custom_stock_status', 10, 2);
php wordpress woocommerce status stock
add a comment |
up vote
0
down vote
favorite
Good day,
Im using this code, but stock status is still "In stock" and "Out of stock" but also must be "Preorder" and "On request".
Its happened after Wordpress Jupiter theme update, about few days looking for reason and solution. Can you please help?
/* add custom stock status */
function woocommerce_add_custom_stock_status()
?>
<script type="text/javascript">
jQuery(function()
jQuery('._stock_status_field').not('.custom-stock-status').remove();
);
</script>
<?php
/* update custom status if backorder if varations updated */
$real_stock_status = get_post_meta($_REQUEST['post'], '_stock_status', true );
if($real_stock_status=="onpreorder")
$stock_status = get_post_meta($_REQUEST['post'], '_custom_stock_status', true ); //get status from custom meta
update_post_meta($_REQUEST['post'], '_stock_status', wc_clean( $stock_status ));
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'onpreorder' => __( 'Preorder', 'woocommerce' ),
'onrequest' => __( 'On request', 'woocommerce' ),
'eof' => __( 'End of life', 'woocommerce' ),
), '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', 'woocommerce_add_custom_stock_status');
/* save custom stock status */
function woocommerce_save_custom_stock_status( $product_id )
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
update_post_meta( $product_id, '_custom_stock_status', wc_clean( $_POST['_stock_status'] ) ); //save another custom meta since '_stock_status' will be overridden
add_action('woocommerce_process_product_meta', 'woocommerce_save_custom_stock_status',99,1);
/* get custom stock status */
function get_custom_stock_status( $data, $product )
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $product->stock_status )
case 'instock':
$data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
case 'onpreorder':
$data = array( 'availability' => __( 'Preorder', 'woocommerce' ), 'class' => 'on-preorder' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'On request', 'woocommerce' ), 'class' => 'on-request' );
break;
case 'eof':
$data = array( 'availability' => __( 'End of life', 'woocommerce' ), 'class' => 'end-of-life' );
break;
return $data;
add_action('woocommerce_get_availability', 'get_custom_stock_status', 10, 2);
php wordpress woocommerce status stock
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Good day,
Im using this code, but stock status is still "In stock" and "Out of stock" but also must be "Preorder" and "On request".
Its happened after Wordpress Jupiter theme update, about few days looking for reason and solution. Can you please help?
/* add custom stock status */
function woocommerce_add_custom_stock_status()
?>
<script type="text/javascript">
jQuery(function()
jQuery('._stock_status_field').not('.custom-stock-status').remove();
);
</script>
<?php
/* update custom status if backorder if varations updated */
$real_stock_status = get_post_meta($_REQUEST['post'], '_stock_status', true );
if($real_stock_status=="onpreorder")
$stock_status = get_post_meta($_REQUEST['post'], '_custom_stock_status', true ); //get status from custom meta
update_post_meta($_REQUEST['post'], '_stock_status', wc_clean( $stock_status ));
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'onpreorder' => __( 'Preorder', 'woocommerce' ),
'onrequest' => __( 'On request', 'woocommerce' ),
'eof' => __( 'End of life', 'woocommerce' ),
), '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', 'woocommerce_add_custom_stock_status');
/* save custom stock status */
function woocommerce_save_custom_stock_status( $product_id )
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
update_post_meta( $product_id, '_custom_stock_status', wc_clean( $_POST['_stock_status'] ) ); //save another custom meta since '_stock_status' will be overridden
add_action('woocommerce_process_product_meta', 'woocommerce_save_custom_stock_status',99,1);
/* get custom stock status */
function get_custom_stock_status( $data, $product )
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $product->stock_status )
case 'instock':
$data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
case 'onpreorder':
$data = array( 'availability' => __( 'Preorder', 'woocommerce' ), 'class' => 'on-preorder' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'On request', 'woocommerce' ), 'class' => 'on-request' );
break;
case 'eof':
$data = array( 'availability' => __( 'End of life', 'woocommerce' ), 'class' => 'end-of-life' );
break;
return $data;
add_action('woocommerce_get_availability', 'get_custom_stock_status', 10, 2);
php wordpress woocommerce status stock
Good day,
Im using this code, but stock status is still "In stock" and "Out of stock" but also must be "Preorder" and "On request".
Its happened after Wordpress Jupiter theme update, about few days looking for reason and solution. Can you please help?
/* add custom stock status */
function woocommerce_add_custom_stock_status()
?>
<script type="text/javascript">
jQuery(function()
jQuery('._stock_status_field').not('.custom-stock-status').remove();
);
</script>
<?php
/* update custom status if backorder if varations updated */
$real_stock_status = get_post_meta($_REQUEST['post'], '_stock_status', true );
if($real_stock_status=="onpreorder")
$stock_status = get_post_meta($_REQUEST['post'], '_custom_stock_status', true ); //get status from custom meta
update_post_meta($_REQUEST['post'], '_stock_status', wc_clean( $stock_status ));
woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
'instock' => __( 'In stock', 'woocommerce' ),
'outofstock' => __( 'Out of stock', 'woocommerce' ),
'onpreorder' => __( 'Preorder', 'woocommerce' ),
'onrequest' => __( 'On request', 'woocommerce' ),
'eof' => __( 'End of life', 'woocommerce' ),
), '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', 'woocommerce_add_custom_stock_status');
/* save custom stock status */
function woocommerce_save_custom_stock_status( $product_id )
update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
update_post_meta( $product_id, '_custom_stock_status', wc_clean( $_POST['_stock_status'] ) ); //save another custom meta since '_stock_status' will be overridden
add_action('woocommerce_process_product_meta', 'woocommerce_save_custom_stock_status',99,1);
/* get custom stock status */
function get_custom_stock_status( $data, $product )
$stock_status = get_post_meta($product->id , '_stock_status' , true );
switch( $product->stock_status )
case 'instock':
$data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'in-stock' );
break;
case 'outofstock':
$data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
break;
case 'onpreorder':
$data = array( 'availability' => __( 'Preorder', 'woocommerce' ), 'class' => 'on-preorder' );
break;
case 'onrequest':
$data = array( 'availability' => __( 'On request', 'woocommerce' ), 'class' => 'on-request' );
break;
case 'eof':
$data = array( 'availability' => __( 'End of life', 'woocommerce' ), 'class' => 'end-of-life' );
break;
return $data;
add_action('woocommerce_get_availability', 'get_custom_stock_status', 10, 2);
php wordpress woocommerce status stock
php wordpress woocommerce status stock
asked Nov 9 at 18:45
Artur Butkevitsus
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231650%2fwoocommerce-stock-status-in-shop-page-and-product-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown