WPOWCPDF_InvoicesCompatibilityWC_Core

WooCommerce Compatibility Utility Class.

Defined (1)

The class is defined in the following location(s).

/includes/compatibility/class-wc-core-compatibility.php  
  1. class WC_Core { 
  2.  
  3. /** 
  4. * Backports wc_get_order() to pre-2.2.0 
  5. * @since 4.3.0 
  6. * @return \WC_Order $order order object 
  7. */ 
  8. public static function get_order( $order_id ) { 
  9.  
  10. if ( function_exists( 'wc_get_order' ) ) { 
  11.  
  12. return wc_get_order( $order_id ); 
  13.  
  14. } else { 
  15.  
  16. return new \WC_Order( $order_id ); 
  17.  
  18.  
  19. /** 
  20. * Backports wc_checkout_is_https() to 2.4.x 
  21. * @since 4.3.0 
  22. * @return bool 
  23. */ 
  24. public static function wc_checkout_is_https() { 
  25.  
  26. if ( self::is_wc_version_gte_2_5() ) { 
  27.  
  28. return wc_checkout_is_https(); 
  29.  
  30. } else { 
  31.  
  32. return wc_site_is_https() || 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || class_exists( 'WordPressHTTPS' ) || strstr( wc_get_page_permalink( 'checkout' ), 'https:' ); 
  33.  
  34.  
  35. /** 
  36. * Backports wc_help_tip() to WC 2.4.x 
  37. * @link https://github.com/woothemes/woocommerce/pull/9417 
  38. * @since 4.2.0 
  39. * @param string $tip help tip content, HTML allowed if $has_html is true 
  40. * @param bool $has_html false by default, true to indicate tip content has HTML 
  41. * @return string help tip HTML, a <span> in WC 2.5, <img> in WC 2.4 
  42. */ 
  43. public static function wc_help_tip( $tip, $has_html = false ) { 
  44.  
  45. if ( self::is_wc_version_gte_2_5() ) { 
  46.  
  47. return wc_help_tip( $tip, $has_html ); 
  48.  
  49. } else { 
  50.  
  51. $tip = $has_html ? wc_sanitize_tooltip( $tip ) : esc_attr( $tip ); 
  52.  
  53. return sprintf( '<img class="help_tip" data-tip="%1$s" src="%2$s" height="16" width="16" />', $tip, esc_url( WC()->plugin_url() ) . '/assets/images/help.png' ); 
  54.  
  55.  
  56. /** 
  57. * Helper method to get the version of the currently installed WooCommerce 
  58. * @since 3.0.0 
  59. * @return string woocommerce version number or null 
  60. */ 
  61. protected static function get_wc_version() { 
  62.  
  63. return defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null; 
  64.  
  65.  
  66. /** 
  67. * Determines if the installed version of WooCommerce is 2.2.0 or greater. 
  68. * @since 4.2.0 
  69. * @return bool 
  70. */ 
  71. public static function is_wc_version_gte_2_2() { 
  72. return self::get_wc_version() && version_compare( self::get_wc_version(), '2.2', '>=' ); 
  73.  
  74.  
  75. /** 
  76. * Determines if the installed version of WooCommerce is less than 2.2.0 
  77. * @since 4.2.0 
  78. * @return bool 
  79. */ 
  80. public static function is_wc_version_lt_2_2() { 
  81. return self::get_wc_version() && version_compare( self::get_wc_version(), '2.2', '<' ); 
  82.  
  83.  
  84. /** 
  85. * Determines if the installed version of WooCommerce is 2.5.0 or greater. 
  86. * @since 4.2.0 
  87. * @return bool 
  88. */ 
  89. public static function is_wc_version_gte_2_5() { 
  90. return self::get_wc_version() && version_compare( self::get_wc_version(), '2.5', '>=' ); 
  91.  
  92.  
  93. /** 
  94. * Determines if the installed version of WooCommerce is less than 2.5.0 
  95. * @since 4.2.0 
  96. * @return bool 
  97. */ 
  98. public static function is_wc_version_lt_2_5() { 
  99. return self::get_wc_version() && version_compare( self::get_wc_version(), '2.5', '<' ); 
  100.  
  101.  
  102. /** 
  103. * Determines if the installed version of WooCommerce is 2.6.0 or greater. 
  104. * @since 4.4.0 
  105. * @return bool 
  106. */ 
  107. public static function is_wc_version_gte_2_6() { 
  108. return self::get_wc_version() && version_compare( self::get_wc_version(), '2.6', '>=' ); 
  109.  
  110.  
  111. /** 
  112. * Determines if the installed version of WooCommerce is less than 2.6.0 
  113. * @since 4.4.0 
  114. * @return bool 
  115. */ 
  116. public static function is_wc_version_lt_2_6() { 
  117. return self::get_wc_version() && version_compare( self::get_wc_version(), '2.6', '<' ); 
  118.  
  119.  
  120. /** 
  121. * Determines if the installed version of WooCommerce is 3.0.0 or greater. 
  122. * @since 4.6.0-dev 
  123. * @return bool 
  124. */ 
  125. public static function is_wc_version_gte_3_0() { 
  126. return self::get_wc_version() && version_compare( self::get_wc_version(), '3.0', '>=' ); 
  127.  
  128.  
  129. /** 
  130. * Determines if the installed version of WooCommerce is less than 3.0.0 
  131. * @since 4.6.0-dev 
  132. * @return bool 
  133. */ 
  134. public static function is_wc_version_lt_3_0() { 
  135. return self::get_wc_version() && version_compare( self::get_wc_version(), '3.0', '<' ); 
  136.  
  137. /** 
  138. * Returns true if the installed version of WooCommerce is greater than $version 
  139. * @since 2.0.0 
  140. * @param string $version the version to compare 
  141. * @return boolean true if the installed version of WooCommerce is > $version 
  142. */ 
  143. public static function is_wc_version_gt( $version ) { 
  144. return self::get_wc_version() && version_compare( self::get_wc_version(), $version, '>' ); 
  145.  
  146.  
  147. /** WordPress core ******************************************************/ 
  148.  
  149.  
  150. /** 
  151. * Normalizes a WooCommerce page screen ID. 
  152. * Needed because WordPress uses a menu title (which is translatable), not slug, to generate screen ID. 
  153. * See details in: https://core.trac.wordpress.org/ticket/21454 
  154. * TODO: Add WP version check when https://core.trac.wordpress.org/ticket/18857 is addressed {BR 2016-12-12} 
  155. * @since 4.6.0-dev 
  156. * @param string $slug The slug for the screen ID to normalize (minus `woocommerce_page_`). 
  157. * @return string Normalized screen ID. 
  158. */ 
  159. public static function normalize_wc_screen_id( $slug = 'wc-settings' ) { 
  160.  
  161. // The textdomain usage is intentional here, we need to match the menu title. 
  162. $prefix = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); 
  163.  
  164. return $prefix . '_page_' . $slug; 
  165.  
  166.