PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

woocommerce_wp_checkbox() has the opossite behavior

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi,

i'm setting custom field programmatically like:

$checkbox_value = get_post_meta( $post->ID, 'xml_exempt', true );
if( empty( $checkbox_value ) ){
$checkbox_value = '';
}
woocommerce_wp_checkbox(
array(
'id' => 'xml_exempt',
'label' => __('Αφαίρεση από τα XML', 'woocommerce' ),
'description' => __( 'Επιλέξτε αν θέλετε να εξαιρέσετε το συγκεκριμένο προϊόν από τα XML', 'woocommerce' ),
'value' => $checkbox_value,
)
);

I have added the field as checkbox through meta fields.

the custom field works as expected when editing through the woocommerce dashboard.

however it has the exact opossite behavior in BEAR, meaning when i enable it, it switches off and vise-versa.

could you please help me out?

thank you in advance for your time,

Menelaos

 

Hello

Please drop  me  wp-admin access - https://share.pluginus.net/image/i20210618130558.png ->https://share.pluginus.net/image/i20210618130637.png I will check  it

i did so.

the fields in question are: mono_paralavi and xml_exempt

the problem is that the checkbox works with 0 and 1

But you work with the string"yes"

My  test - https://c2n.me/4gx06WA

Hi Mr Pablo,

I understand what you're trying to show. however i didn't make the choise to make it"work" like that, rather it's a woocommerce standard way of working.

The custom woocommerce_wp_checkbox() field is automatically saved in the wp_postsmeta table as"yes" or"no".

I have pasted bellow the whole plugin that is populating these fields and you can clearly see that i do not manipulate them in any way.

In order to make it work with 1 or 0, i have to write a lot of code as firstly i will to manipulate the fields on the save_product_custom_fields function so they will be written as 1 or 0(which is something very easy).

The difficult(not really difficult but it would need a lot of time) part would be to edit the code that these fields change the product behavior which is in 10+ different places and plugins.

 

Is it possible to make the checkboxes work in the standard woocommerce way in a future update?

if yes, how much time(approximatelly) will be needed?

thank you in advance for your time,

Menelaos

 

<?php
add_action(
'woocommerce_product_options_general_product_data',
'general_product_custom_fields'
);

// Add a custom field to general product data.
function general_product_custom_fields() {

global $post;

$checkbox_value = get_post_meta( $post->ID, 'xml_exempt', true );
if( empty( $checkbox_value ) ){
$checkbox_value = '';
}
woocommerce_wp_checkbox(
array(
'id' => 'xml_exempt',
'label' => __('Αφαίρεση από τα XML', 'woocommerce' ),
'description' => __( 'Επιλέξτε αν θέλετε να εξαιρέσετε το συγκεκριμένο προϊόν από τα XML', 'woocommerce' ),
'value' => $checkbox_value,
)
);

$mono_paralavi_value = get_post_meta( $post->ID, 'mono_paralavi', true );
if( empty( $mono_paralavi_value ) ){
$mono_paralavi_value = '';
}
woocommerce_wp_checkbox(
array(
'id' => 'mono_paralavi',
'label' => __('Μόνο Παραλαβή', 'woocommerce' ),
'description' => __( 'Επιλέξτε αν θέλετε να ενεργοποιήσετε παραλαβή μόνο από το κατάστημα', 'woocommerce' ),
'value' => $mono_paralavi_value,
)
);

}

add_action(
'woocommerce_process_product_meta',
'save_product_custom_fields'
);

// Save the custom field in the DB.
function save_product_custom_fields($id) {

update_post_meta(
$id,
'mono_paralavi',
$_POST['mono_paralavi']
);
update_post_meta(
$id,
'xml_exempt',
$_POST['xml_exempt']
);

}
?>

Hello

I'll pass this to the developers, but unfortunately I don't know when the next update will be.