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);









share|improve this question

























    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);









    share|improve this question























      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);









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 18:45









      Artur Butkevitsus

      11




      11



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo