Answer the question
In order to leave comments, you need to log in
How to save 2 checkboxes in admin in woocommerce?
Example
add_action( 'woocommerce_product_data_panels', 'custom_added_tabs_panel' );
function custom_added_tabs_panel() {
?>
<div id="status_panel_product_data" class="panel woocommerce_options_panel">
<div class="options_group">
<?php
woocommerce_wp_checkbox(array(
'id' => 'status-one',
'wrapper_class' => 'show_if_simple',
'label' => 'Статус 1'
));
?>
</div>
<div class="options_group">
<?php
woocommerce_wp_checkbox(array(
'id' => 'status-two',
'wrapper_class' => 'show_if_simple',
'label' => 'Статус 2'
));
?>
</div>
</div>
<?php
}
add_action( 'woocommerce_process_product_meta', 'custom_fields_save', 10 );
function custom_fields_save( $post_id ) {
$product = wc_get_product( $post_id );
$checkbox_field = (isset( $_POST['status-one'] ) || isset($_POST['status-two'] )) ? 'yes' : 'no';
$product->update_meta_data( 'status-one, status-two', $checkbox_field );
$product->save();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question