// Manage options hooks
add_action( 'woocommerce_product_options_inventory_product_data', 'my_woocommerce_product_options_inventory_product_data' );
add_action( 'woocommerce_process_product_meta', 'my_woocommerce_process_product_meta' );
/**
* Hook handler for woocommerce_product_options_inventory_product_data.
*
* Echo html code for our options on inventory_product_data option tab
*
* @since 1.0.0
*/
public function my_woocommerce_product_options_inventory_product_data() {
global $product, $post;
$chk_val = get_post_meta ( $post->ID , 'hdke_stock_tracker_checkbox' , true );
$thld_val = get_post_meta ( $post->ID , 'hdke_stock_tracker_threshold' , true );
echo '<div class="options_group">'; // Группировка полей
woocommerce_wp_checkbox( array(
'id' => '_hdke_stock_tracker_checkbox',
'name' => 'hdke_stock_tracker_checkbox',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'Stock tracker', $this->plugin_name ),
'description' => __( 'Enabled stock tracking for this product', $this->plugin_name ),
'cbvalue' => $chk_val ? $chk_val : 'no',
'value' => $chk_val ? $chk_val : 'no'
) );
woocommerce_wp_text_input( array(
'id' => '_hdke_stock_tracker_threshold',
'name' => 'hdke_stock_tracker_threshold',
'label' => __( 'Stock threshold', $this->plugin_name ),
'description' => __( 'Input min threshold of stock variation to include this product in dk b2b order list.', $this->plugin_name ),
'style' => 'width: 100px;',
'wrapper_class' => 'show_if_simple show_if_variable',
'desc_tip' => 'true',
'type' => 'number',
'custom_attributes' => array('step' => 'any', 'min' => '0', ),
'value' => $thld_val ? $thld_val : 0
) );
echo '</div>';
}
/**
* Hook handler for woocommerce_process_product_meta.
*
* Save user settings of our options
*
* @since 1.0.0
*/
public function my_woocommerce_process_product_meta() {
global $product, $post;
$chk_val = isset($_POST['hdke_stock_tracker_checkbox']) ? 'yes' : 'no';
$thld_val = empty($_POST['hdke_stock_tracker_threshold']) ? '0' : $_POST['hdke_stock_tracker_threshold'];
update_post_meta( $post->ID, 'hdke_stock_tracker_checkbox', $chk_val );
update_post_meta( $post->ID, 'hdke_stock_tracker_threshold', $thld_val );
}