0

I have a custom checkbox field on the general settings of my Woocommerce products.

I also have 5 or so functions that all do what I want them to do. These are currently housed in my child theme's functions.php file.

I would like to have it so, once the checkbox is checked on the Product Admin Page and it is saved... all of those functions now become active and affect only the said product.

Is there an easier, quick way of doing this rather than adding the condition if ( 'yes' == $custom_field && $otherstuff ) on every single function manually?

1 Answer 1

0
function start_all(){
    $option = get_option($name);
    if ( 'yes' == $custom_field && $otherstuff ){
         function_1();
         function_2();
         function_3();
    }

}

plase it in functions and call whit hook you need - this is just an example

2
  • I have always been told that housing functions inside of functions/actions & filters inside of functions was bad practice... was I told wrong? How could I be sure this only targets the product at hand? Commented Apr 12, 2020 at 17:27
  • as I said, this is just an example, from what i know - that the main problem of holding in function - actions and filters is misfireing ( starting in wrong time ) or dificaltis in finding when call from some other callbac. when used inside shoud be very carefyl... allaws be carefyl whit actions and hooks.. the actions and hook on its oun are functions...int is good the use of actions to be out of function so when functions.php is reed the hook will be seen and act on it...in function - the action and filters are not seen before calld. Commented Apr 12, 2020 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.