Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Custom field using "woocommerce_customer_meta_fields" hook #19585

Closed
Phatza opened this issue Mar 31, 2018 · 2 comments
Closed

Save Custom field using "woocommerce_customer_meta_fields" hook #19585

Phatza opened this issue Mar 31, 2018 · 2 comments

Comments

@Phatza
Copy link

Phatza commented Mar 31, 2018

Hi there,

I've tried to add custom checkbox field into Admin Edit User Profil Page using the filter hook "woocommerce_customer_meta_fields". The field is displayed to the right position and I can update the value 馃憤.
(I'm using Woocommerce version 3.3.4)

The problem is that after the value's update (0 by default) the custom field disappeared.
The checkbox's field is expecting 0 or 1 as value.
When the value is equal to 0 the field is visible, but when I change the value to 1 it is not.

This is the snippet I've added in my functions.php :

add_filter( 'woocommerce_customer_meta_fields', 'filter_woocommerce_customer_meta_fields', 10, 1 );
    function filter_woocommerce_customer_meta_fields( $array ) {

        $array += array(
            'enable_sms_alert' => array(
                'title' => 'Activation de l\'alerte SMS',
                'fields' => array(
                    'enable_sms_alert' => array(
                        'label' => 'Cochez la case pour activer l\'alerte SMS',
                        'description' => 'Si l\'option est activ茅e, vous recevrez des alertes SMS (au num茅ro renseigner) pour les v茅hicules pr茅sents dans votre Wishlist',
                        'type' => 'checkbox',
                        'class' => 'enable_sms_alert'
                    )
                )
            )
        );
        return $array;
    }

I've tried to change the type field to text (number isnt output) and I've noticed that when the value is a string like "Hello World" the field is still visible, but if I change the value to 1 or another number than 0 the field is not displayed anymore.

Any ideas ?

Thanks for your time 馃槂

Regards

EDITED PART:

I've notice that the hooks arent triggered when I've a custom value different of 0 or "letter string".

@Phatza Phatza closed this as completed Apr 2, 2018
@Phatza Phatza reopened this Apr 2, 2018
@claudiulodro
Copy link
Contributor

I'm not exactly sure what you're saying, but your code snippet works fine for me:

screen shot 2018-04-02 at 10 25 29 am

screen shot 2018-04-02 at 10 25 41 am

I would look through WC_Admin_Settings to see how it handles checkbox inputs and compare that to the input you're giving it to make sure it's all correct.

Closing this issue as it's a development support request and not a bug in the core plugin. For future development questions I recommend joining the WooCommerce community Slack using the form at the bottom of this page.

@Phatza
Copy link
Author

Phatza commented Apr 3, 2018

Hi,

I've made no changes but it seems to work today.. (this could be the april fool ^^).
This error could be produced by my server ?

Sorry for the waste of time.
i'll give a try to the slack's channel.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants