Function only works on page refresh
Question
I’ve written the following function to change currencies depending on a form submission.
if($from=="Antrim" || $from=="Armagh" || $from=="Down" || $from=="Fermanagh" || $from=="Derry" || $from=="Tyrone"){
$mycountry ="GB";
}
else{
$mycountry ="IE";
}
add_action( 'wc_price_based_country_before_frontend_init', 'my_function', 10, 1 );
function my_function($mycountry) {
return $mycountry;
}
if(wcpbc_set_woocommerce_country($mycountry)){
echo"wcpbc_set_woocommerce_country($mycountry) Success;";
}
else{
echo "wcpbc_set_woocommerce_country($mycountry) Failed";
}
my_function($mycountry);
The output of the script is wcpbc_set_woocommerce_country(GB) Failed and the currency is not updated.
However, if I refresh the form data or add another order the output is still wcpbc_set_woocommerce_country(GB) Failed
But the currency has been updated to £.
Any idea what I’m doing wrong?
0
2 months
0 Answers
18 views
0
Leave an answer
You must login or register to add a new answer .