Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI have an issue with a product type option checkbox. The value is saved correctly in the database. If the value is yes the checkbox is unchecked.
The code that I wrote below
<?php
function add_octopus_child_option( $product_type_options ) {
$product_type_options['_childocto'] = array(
'id' => '_childocto',
'wrapper_class' => 'show_if_octopus',
'label' => __( 'Gekoppeld', 'woocommerce' ),
'description' => __( 'Vink dit aan indien dit niet het hoofdproduct is.', 'woocommerce' ),
);
return $product_type_options;
}
add_filter( 'product_type_options', 'add_octopus_child_option' );
function save_product_data_octopus($post_id){
$woocommerce_checkbox = isset( $_POST['_childocto'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_childocto', $woocommerce_checkbox );
}
add_action('save_post', 'save_product_data_octopus');
?>
Who can help me with this issue?
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 4 years ago.
Improve this questionI have an issue with a product type option checkbox. The value is saved correctly in the database. If the value is yes the checkbox is unchecked.
The code that I wrote below
<?php
function add_octopus_child_option( $product_type_options ) {
$product_type_options['_childocto'] = array(
'id' => '_childocto',
'wrapper_class' => 'show_if_octopus',
'label' => __( 'Gekoppeld', 'woocommerce' ),
'description' => __( 'Vink dit aan indien dit niet het hoofdproduct is.', 'woocommerce' ),
);
return $product_type_options;
}
add_filter( 'product_type_options', 'add_octopus_child_option' );
function save_product_data_octopus($post_id){
$woocommerce_checkbox = isset( $_POST['_childocto'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_childocto', $woocommerce_checkbox );
}
add_action('save_post', 'save_product_data_octopus');
?>
Who can help me with this issue?
Share Improve this question asked Nov 24, 2020 at 23:40 BenBen 132 bronze badges1 Answer
Reset to default 0I have modified your code please check the below code.
function add_octopus_child_option( $product_type_options ) {
$product_type_options['childocto'] = array(
'id' => '_childocto',
'wrapper_class' => 'show_if_octopus',
'label' => __( 'Gekoppeld', 'woocommerce' ),
'description' => __( 'Vink dit aan indien dit niet het hoofdproduct is.', 'woocommerce' ),
'default' => 'no'
);
return $product_type_options;
}
add_filter( 'product_type_options', 'add_octopus_child_option' );
function save_product_data_octopus($post_id){
$woocommerce_checkbox = isset( $_POST['_childocto'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_childocto', $woocommerce_checkbox );
}
add_action( 'woocommerce_process_product_meta_simple','save_product_data_octopus' );
add_action( 'woocommerce_process_product_meta_variable', 'save_product_data_octopus' );
Try with the above code and if does not work let me know.