PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]
Botoscope is currently in early access

Support Forum

You need to log-in to create request (topic) to the support

atal Error in Background/Cron Tasks: Call to undefined function wc_get_page_screen_id() in woocs_hpos.php

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.

Hi team,

We are encountering a fatal error during automated cron executions. (specifically when background tasks like Jetpack Sync run wc_get_order()).

Fatal error: Uncaught Error: Call to undefined function wc_get_page_screen_id() in wp-content/plugins/woocommerce-currency-switcher/classes/woocs_hpos.php:55
Stack trace:
#0 wp-content/plugins/woocommerce-currency-switcher/index.php(582): WoocsHpos->getOrderScreenId()
#1 wp-content/plugins/woocommerce-currency-switcher/index.php(384): woocs_is_admin_order_edit_context()
#2 wp-includes/class-wp-hook.php(355): {closure}()
#3 wp-includes/plugin.php(206): WP_Hook->apply_filters()
#4 wp-includes/option.php(256): apply_filters()
...
#17 wp-includes/wc-order-functions.php(94): WC_Order_Factory::get_order()
#24 wp-includes/class-wp-hook.php(353): Automattic\Jetpack\Sync\Actions::do_cron_sync()
#27 wp-cron.php(191): do_action_ref_array()

Cause

The function wc_get_page_screen_id() is loaded exclusively inside the admin context (woocommerce/includes/admin/wc-admin-functions.php).

When background workers, WP-CLI, or WP-Cron load orders via wc_get_order(), option filters trigger woocs_is_admin_order_edit_context(), which invokes WoocsHpos::getOrderScreenId(). Since the admin functions file is not loaded in non-admin/cron contexts, it results in an unhandled E_ERROR.

Suggested Fix

In classes/woocs_hpos.php, you can check if the function exists or directly use \Automattic\WooCommerce\Utilities\OrderUtil::get_order_admin_screen():

public function getOrderScreenId(): string {

if ( ! class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) ) {
return 'shop_order';
}

if ( \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) {
if ( function_exists( 'wc_get_page_screen_id' ) ) {
return wc_get_page_screen_id( 'shop-order' );
}
return \Automattic\WooCommerce\Utilities\OrderUtil::get_order_admin_screen();
}

return 'shop_order';
}

Could you please patch this in the next release to prevent background cron processes from failing?

Thanks!