Migrating from the deprecated hooks to woocommerce_get_script_data
Everything began with a comment on my tutorial about password strength meter customization in WooCommerce.
In that tutorial I used wc_password_strength_meter_params
action hook, but since WooCommerce 3.3 this hook cause a PHP warning (notice).
I decided to google it, but I didn’t find any information at all 👻 After that I dived into WooCommerce source code and I found out that all of the below hooks have been deprecated since Woo 3.3:
woocommerce_params
,wc_checkout_params
,wc_cart_params
,wc_geolocation_params
,wc_single_product_params
,wc_address_i18n_params
,wc_cart_fragments_params
,wc_add_to_cart_params
,wc_add_to_cart_variation_params
,wc_country_select_params
,wc_password_strength_meter_params
;
Every hook from the above list has to be replaced with this one – woocommerce_get_script_data
.
I will show you how! Let’s say, that we use something like this on our website.
add_filter( 'wc_checkout_params', 'misha_hook_before' );
function misha_hook_before( $data ) {
// do stuff with the $data array and return it
}
So, here is what we have to do:
- Replace
wc_checkout_params
withwoocommerce_get_script_data
(line 1). - Add one more parameter (
$handle
, line 3) and specify it inadd_filter()
function (line 1). - Depending on the new parameter value, do specific stuff. Of course
switch()
is not necessary, I just used it to show you all the hooks replacements.If
condition can be more than enough.
add_filter( 'woocommerce_get_script_data', 'misha_hook_after', 10, 2 );
function misha_hook_after( $data, $handle ) {
switch( $handle ) :
case 'woocommerce':
// do stuff with the $data array
break;
case 'wc_checkout':
// do stuff with the $data array
break;
case 'wc_cart':
// do stuff
break;
case 'wc_geolocation':
// do stuff
break;
case 'wc_single_product':
// ...
break;
case 'wc_address_i18n':
// ...
break;
case 'wc_cart_fragments':
// ...
break;
case 'wc_add_to_cart':
// ...
break;
case 'wc_add_to_cart_variation':
// ...
break;
case 'wc_country_select':
// ...
break;
case 'wc_password_strength_meter':
// ...
break;
endswitch;
return $data;
}
If you have more useful information about it, or a question, welcome to comments.
Related

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Thanks
Just what I needed.
Gosh, I hate it to stay up to date with Woocommerce
Thank you for your guide. However i couldn’t fix my problem. With the last version, a warning came up on every pages: “Notice: wc_address_i18n_params is deprecated since 3.3.5 version! Use instead woocommerce_get_script_data. in /web/htdocs/www.escapeit.it/home/wp-includes/functions.php on line 4090”
The line 4090 is
Really can’t find wc_address_i18n_params or wc_checkout_params in functions.php, so i cannot replace it with woocommerce_get_script_data. Do you have any idea? Here’s the block of the 4090 line:
Hey Mike,
You shouldn’t search for
wc_address_i18n_params()
in WordPress core files 🙃Here is step by step what you have to do:
1. Deactivate plugins one by one (except WooCommerce of course) and check every time if the notice is disappeared. Once it did, perform search by all files of a specific plugin ( or maybe it already has an updated version available ).
2. If no luck, perform the search by
wc_address_i18n_params
in your current theme files.Damn,
still trouble with wc_cart_fragments
Somehow if I use your solution it gives me an Javascript error on frontpage which crashes every other DHTML stuff.
Everyhhing works fine the moment I remove your solution again.
Any idea?
Hmmmm
just replaced
with
which at least stops the Javascript error.
Could you pls send me the first 2 lines of your
npt_hook_after()
function?Hello, Can i change length of the reset password of woocommerce email reset form ?
I am not needed 12 character with no any added symbol,number etc..Simply use 8 characters