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

Fatal Error in WooCommerce Currency Switcher - Issue with update_meta_data()

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.

I am experiencing a fatal error on my website that appears to be related to the WooCommerce Currency Switcher plugin. The error occurs on line 3414 of the woocs.php file.

Error Details:

Spoiler
[06-Sep-2023 23:02:48 UTC] PHP Fatal error: Uncaught Error: Call to a member function update_meta_data() on bool in /home1/s4fiuh89/public_html/wp-content/plugins/woocommerce-currency-switcher/classes/woocs.php:3414
Stack trace:
#0 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(310): WOOCS->woocommerce_thankyou_order_id(30948)
#1 /home1/s4fiuh89/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(30948, Array)
#2 /home1/s4fiuh89/public_html/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(268): apply_filters('woocommerce_tha...', 30948)
#3 /home1/s4fiuh89/public_html/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(63): WC_Shortcode_Checkout::order_received('30948')
#4 /home1/s4fiuh89/public_html/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(72): WC_Shortcode_Checkout::output('')
#5 /home1/s4fiuh89/public_html/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(95): WC_Shortcodes::shortcode_wrapper(Array, '')
#6 /home1/s4fiuh89/public_html/wp-includes/shortcodes.php(395): WC_Shortcodes::checkout('', '', 'woocommerce_che...')
#7 [internal function]: do_shortcode_tag(Array)
#8 /home1/s4fiuh89/public_html/wp-includes/shortcodes.php(235): preg_replace_callback('/\\[(\\[?)(woocom...', 'do_shortcode_ta...', '[woocommerce_ch...')
#9 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(310): do_shortcode('[woocommerce_ch...')
#10 /home1/s4fiuh89/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters('[woocommerce_ch...', Array)
#11 /home1/s4fiuh89/public_html/wp-includes/post-template.php(256): apply_filters('the_content', '[woocommerce_ch...')
#12 /home1/s4fiuh89/public_html/wp-content/themes/astra/template-parts/single/content-header.php(33): the_content()
#13 /home1/s4fiuh89/public_html/wp-includes/template.php(787): require('/home1/s4fiuh89...')
#14 /home1/s4fiuh89/public_html/wp-includes/template.php(720): load_template('/home1/s4fiuh89...', false, Array)
#15 /home1/s4fiuh89/public_html/wp-includes/general-template.php(206): locate_template(Array, true, false, Array)
#16 /home1/s4fiuh89/public_html/wp-content/themes/astra/inc/template-parts.php(376): get_template_part('template-parts/...')
#17 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(310): astra_entry_content_single_page_template('')
#18 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters('', Array)
#19 /home1/s4fiuh89/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#20 /home1/s4fiuh89/public_html/wp-content/themes/astra/inc/core/theme-hooks.php(452): do_action('astra_entry_con...')
#21 /home1/s4fiuh89/public_html/wp-content/themes/astra/template-parts/content-page.php(26): astra_entry_content_single_page()
#22 /home1/s4fiuh89/public_html/wp-includes/template.php(787): require('/home1/s4fiuh89...')
#23 /home1/s4fiuh89/public_html/wp-includes/template.php(720): load_template('/home1/s4fiuh89...', false, Array)
#24 /home1/s4fiuh89/public_html/wp-includes/general-template.php(206): locate_template(Array, true, false, Array)
#25 /home1/s4fiuh89/public_html/wp-content/themes/astra/inc/class-astra-loop.php(109): get_template_part('template-parts/...', 'page')
#26 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(310): Astra_Loop->template_parts_page('')
#27 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters('', Array)
#28 /home1/s4fiuh89/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#29 /home1/s4fiuh89/public_html/wp-content/themes/astra/inc/class-astra-loop.php(197): do_action('astra_page_temp...')
#30 /home1/s4fiuh89/public_html/wp-content/themes/astra/inc/class-astra-loop.php(174): Astra_Loop->loop_markup(true)
#31 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(310): Astra_Loop->loop_markup_page('')
#32 /home1/s4fiuh89/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters('', Array)
#33 /home1/s4fiuh89/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#34 /home1/s4fiuh89/public_html/wp-content/themes/astra/inc/core/theme-hooks.php(267): do_action('astra_content_p...')
#35 /home1/s4fiuh89/public_html/wp-content/themes/astra/page.php(32): astra_content_page_loop()
#36 /home1/s4fiuh89/public_html/wp-includes/template-loader.php(106): include('/home1/s4fiuh89...')
#37 /home1/s4fiuh89/public_html/wp-blog-header.php(19): require_once('/home1/s4fiuh89...')
#38 /home1/s4fiuh89/public_html/index.php(17): require('/home1/s4fiuh89...')
#39 {main}
thrown in /home1/s4fiuh89/public_html/wp-content/plugins/woocommerce-currency-switcher/classes/woocs.php on line 3414

this error was repeated 8 times in the last day

Environment:

WordPress Version: 6.3.1
WooCommerce Version: 8.0.3
WooCommerce Currency Switcher Version: 2.4.1
Theme in Use: Astra (Child) 3.3

I have implemented a temporary fix by modifying my functions.php file, but I would like to know if there is a more permanent solution.

Spoiler

// Override the woocommerce_thankyou_order_id function to prevent fatal error ( public_html/wp-content/plugins/woocommerce-currency-switcher/classes/woocs.php:3414 linea error 3414)
function override_woocommerce_thankyou_order_id($order_id) {
$woocs = new WOOCS(); // Assuming WOOCS class is available
$currencies = $woocs->get_currencies();
$order = wc_get_order($order_id);

if (is_object($order) && method_exists($order, 'update_meta_data')) {
$order->update_meta_data('_woocs_order_rate', $currencies[$woocs->current_currency]['rate']);
$order->update_meta_data('_woocs_order_base_currency', $woocs->default_currency);
$order->update_meta_data('_woocs_order_currency_changed_mannualy', 0);
$order->save();
} else {
error_log('El objeto $order no es válido o no tiene el método update_meta_data.');
}
}

// Remove the original action
remove_action('woocommerce_thankyou', array('WOOCS', 'woocommerce_thankyou_order_id'));

// Add the new action
add_action('woocommerce_thankyou', 'override_woocommerce_thankyou_order_id');

 

Hello

Thank  you  for  your  cooperation

Yes we will fixed [Task is created for this fix]