Sin descripción

Helper.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace MailPoet\WooCommerce;
  3. if (!defined('ABSPATH')) exit;
  4. class Helper {
  5. public function isWooCommerceActive() {
  6. return class_exists('WooCommerce');
  7. }
  8. public function WC() {
  9. return WC();
  10. }
  11. public function wcGetCustomerOrderCount($userId) {
  12. return wc_get_customer_order_count($userId);
  13. }
  14. public function wcGetOrder($order = false) {
  15. return wc_get_order($order);
  16. }
  17. public function wcGetOrders(array $args) {
  18. return wc_get_orders($args);
  19. }
  20. public function wcPrice($price, array $args = []) {
  21. return wc_price($price, $args);
  22. }
  23. public function wcGetProduct($theProduct = false) {
  24. return wc_get_product($theProduct);
  25. }
  26. public function getWoocommerceCurrency() {
  27. return get_woocommerce_currency();
  28. }
  29. public function getWoocommerceCurrencySymbol() {
  30. return get_woocommerce_currency_symbol();
  31. }
  32. public function woocommerceFormField($key, $args, $value) {
  33. return woocommerce_form_field($key, $args, $value);
  34. }
  35. public function wcLightOrDark($color, $dark, $light) {
  36. return wc_light_or_dark($color, $dark, $light);
  37. }
  38. public function wcHexIsLight($color) {
  39. return wc_hex_is_light($color);
  40. }
  41. public function getOrdersCountCreatedBefore($dateTime) {
  42. global $wpdb;
  43. $result = $wpdb->get_var( "
  44. SELECT DISTINCT count(p.ID) FROM {$wpdb->prefix}posts as p
  45. WHERE p.post_type = 'shop_order' AND p.post_date < '{$dateTime}'
  46. " );
  47. return (int)$result;
  48. }
  49. public function getRawPrice($price, array $args = []) {
  50. $htmlPrice = $this->wcPrice($price, $args);
  51. return html_entity_decode(strip_tags($htmlPrice));
  52. }
  53. public function getAllowedCountries(): array {
  54. return (new \WC_Countries)->get_allowed_countries() ?? [];
  55. }
  56. }