Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type', 99);
- 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' ),
- 'onrequest' => __( 'Αποστολή σε 4-7 εργάσιμες', '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_process_product_meta', 'save_custom_stock_status',10,1);
- function save_custom_stock_status( $product_id ) {
- global $wpdb;
- $wpdb->update($wpdb->prefix .'wc_product_meta_lookup', array('stock_status'=>wc_clean( $_POST['_stock_status'])), array('product_id'=>$product_id));
- update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
- }
- add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 9, 2);
- function woocommerce_get_custom_availability( $data, $product ) {
- switch( get_post_meta( $product -> get_ID(), '_stock_status', true ) ) {
- 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 'onrequest':
- $data = array( 'availability' => __( 'Αποστολή σε 4-7 εργάσιμες', 'woocommerce' ), 'class' => 'on-request' );
- break;
- }
- return $data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement