From 5c2b34e9da38414c698eaaf6ba6c047652c08286 Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Wed, 27 Mar 2019 17:11:40 +0100 Subject: [PATCH] Move WC functions to WC Helper --- lib/WP/Functions.php | 12 ------------ lib/WooCommerce/Helper.php | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/WP/Functions.php b/lib/WP/Functions.php index 6152100fee..0903360b2f 100644 --- a/lib/WP/Functions.php +++ b/lib/WP/Functions.php @@ -31,18 +31,6 @@ class Functions { return call_user_func_array('add_action', func_get_args()); } - function wcGetCustomerOrderCount($user_id) { - return call_user_func_array('wc_get_customer_order_count', [$user_id]); - } - - function wcGetOrder($order = false) { - return call_user_func_array('wc_get_order', [$order]); - } - - function wcPrice($price, array $args = array()) { - return call_user_func_array('wc_price', [$price, $args]); - } - function __($text, $domain = 'default') { return __($text, $domain); } diff --git a/lib/WooCommerce/Helper.php b/lib/WooCommerce/Helper.php index c5df9a291c..b24f6545f6 100644 --- a/lib/WooCommerce/Helper.php +++ b/lib/WooCommerce/Helper.php @@ -5,4 +5,25 @@ class Helper { function isWooCommerceActive() { return class_exists('WooCommerce'); } + function wcGetCustomerOrderCount($user_id) { + if (! is_callable('wc_get_customer_order_count')) { + throw new \Exception("function 'wc_get_customer_order_count' not found!"); + } + return wc_get_customer_order_count($user_id); + } + function wcGetOrder($order = false) { + if (! is_callable('wc_get_order')) { + throw new \Exception("function 'wc_get_order' not found!"); + + } + return wc_get_order($order); + } + + function wcPrice($price, array $args = array()) { + if (! is_callable('wc_price')) { + throw new \Exception("function 'wc_price' not found!"); + + } + return wc_price($price, $args); + } }