Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1. add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type', 99);
  2. function add_custom_stock_type() {
  3.     ?>
  4.     <script type="text/javascript">
  5.     jQuery(function(){
  6.         jQuery('._stock_status_field').not('.custom-stock-status').remove();
  7.     });
  8.     </script>
  9.     <?php  
  10.     woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
  11.         'instock' => __( 'In stock', 'woocommerce' ),
  12.         'outofstock' => __( 'Out of stock', 'woocommerce' ),
  13.         'onrequest' => __( 'Αποστολή σε 4-7 εργάσιμες', 'woocommerce' ),
  14.     ), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
  15. }
  16.  
  17. add_action('woocommerce_process_product_meta', 'save_custom_stock_status',10,1);
  18. function save_custom_stock_status( $product_id ) {
  19.     global $wpdb;
  20.  
  21.     $wpdb->update($wpdb->prefix .'wc_product_meta_lookup', array('stock_status'=>wc_clean( $_POST['_stock_status'])), array('product_id'=>$product_id));
  22.    
  23.     update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
  24. }
  25.  
  26. add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 9, 2);
  27. function woocommerce_get_custom_availability( $data, $product ) {
  28.     switch( get_post_meta( $product -> get_ID(), '_stock_status', true ) ) {
  29.         case 'instock':
  30.             $data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'in-stock' );
  31.         break;
  32.         case 'outofstock':
  33.             $data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
  34.         break;
  35.         case 'onrequest':
  36.             $data = array( 'availability' => __( 'Αποστολή σε 4-7 εργάσιμες', 'woocommerce' ), 'class' => 'on-request' );
  37.         break;
  38.     }
  39.     return $data;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement