Advertisement
Guest User

Untitled

a guest
May 16th, 2017
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. /*adding stock option*/
  2.  
  3. function add_custom_stock_type() {
  4. ?>
  5. <script type="text/javascript">
  6. jQuery(function(){
  7. jQuery('._stock_status_field').not('.custom-stock-status').remove();
  8. });
  9. </script>
  10. <?php
  11.  
  12. woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
  13. 'instock' => __( 'In stock', 'woocommerce' ),
  14. 'outofstock' => __( 'Out of stock', 'woocommerce' ),
  15. 'onhold' => __( 'On Hold', 'woocommerce' ), // The new option !!!
  16. ), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
  17. }
  18. add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');
  19.  
  20. function save_custom_stock_status( $product_id ) {
  21. update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
  22. }
  23. add_action('woocommerce_process_product_meta', 'save_custom_stock_status',99,1);
  24.  
  25. function woocommerce_get_custom_availability( $data, $product ) {
  26. switch( $product->get_stock_status ) {
  27. case 'onhold':
  28. $data = array( 'availability' => __( 'On Hold', 'woocommerce' ), 'class' => 'on-hold' );
  29. break;
  30. case 'instock':
  31. $data = array( 'availability' => __( 'In stock2', 'woocommerce' ), 'class' => 'in-stock' );
  32. break;
  33. case 'outofstock':
  34. $data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
  35. break;
  36. }
  37. return $data;
  38. }
  39. add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 3, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement