WooCommerce

Main WooCommerce Class.

Defined (1)

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

/woocommerce.php  
  1. final class WooCommerce { 
  2.  
  3. /** 
  4. * WooCommerce version. 
  5. * @var string 
  6. */ 
  7. public $version = '3.0.6'; 
  8.  
  9. /** 
  10. * The single instance of the class. 
  11. * @var WooCommerce 
  12. * @since 2.1 
  13. */ 
  14. protected static $_instance = null; 
  15.  
  16. /** 
  17. * Session instance. 
  18. * @var WC_Session|WC_Session_Handler 
  19. */ 
  20. public $session = null; 
  21.  
  22. /** 
  23. * Query instance. 
  24. * @var WC_Query 
  25. */ 
  26. public $query = null; 
  27.  
  28. /** 
  29. * Product factory instance. 
  30. * @var WC_Product_Factory 
  31. */ 
  32. public $product_factory = null; 
  33.  
  34. /** 
  35. * Countries instance. 
  36. * @var WC_Countries 
  37. */ 
  38. public $countries = null; 
  39.  
  40. /** 
  41. * Integrations instance. 
  42. * @var WC_Integrations 
  43. */ 
  44. public $integrations = null; 
  45.  
  46. /** 
  47. * Cart instance. 
  48. * @var WC_Cart 
  49. */ 
  50. public $cart = null; 
  51.  
  52. /** 
  53. * Customer instance. 
  54. * @var WC_Customer 
  55. */ 
  56. public $customer = null; 
  57.  
  58. /** 
  59. * Order factory instance. 
  60. * @var WC_Order_Factory 
  61. */ 
  62. public $order_factory = null; 
  63.  
  64. /** 
  65. * Structured data instance. 
  66. * @var WC_Structured_Data 
  67. */ 
  68. public $structured_data = null; 
  69.  
  70. /** 
  71. * Array of deprecated hook handlers. 
  72. * @var array of WC_Deprecated_Hooks 
  73. */ 
  74. public $deprecated_hook_handlers = array(); 
  75.  
  76. /** 
  77. * Main WooCommerce Instance. 
  78. * Ensures only one instance of WooCommerce is loaded or can be loaded. 
  79. * @since 2.1 
  80. * @static 
  81. * @see WC() 
  82. * @return WooCommerce - Main instance. 
  83. */ 
  84. public static function instance() { 
  85. if ( is_null( self::$_instance ) ) { 
  86. self::$_instance = new self(); 
  87. return self::$_instance; 
  88.  
  89. /** 
  90. * Cloning is forbidden. 
  91. * @since 2.1 
  92. */ 
  93. public function __clone() { 
  94. wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' ); 
  95.  
  96. /** 
  97. * Unserializing instances of this class is forbidden. 
  98. * @since 2.1 
  99. */ 
  100. public function __wakeup() { 
  101. wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' ); 
  102.  
  103. /** 
  104. * Auto-load in-accessible properties on demand. 
  105. * @param mixed $key 
  106. * @return mixed 
  107. */ 
  108. public function __get( $key ) { 
  109. if ( in_array( $key, array( 'payment_gateways', 'shipping', 'mailer', 'checkout' ) ) ) { 
  110. return $this->$key(); 
  111.  
  112. /** 
  113. * WooCommerce Constructor. 
  114. */ 
  115. public function __construct() { 
  116. $this->define_constants(); 
  117. $this->includes(); 
  118. $this->init_hooks(); 
  119.  
  120. do_action( 'woocommerce_loaded' ); 
  121.  
  122. /** 
  123. * Hook into actions and filters. 
  124. * @since 2.3 
  125. */ 
  126. private function init_hooks() { 
  127. register_activation_hook( __FILE__, array( 'WC_Install', 'install' ) ); 
  128. add_action( 'after_setup_theme', array( $this, 'setup_environment' ) ); 
  129. add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 ); 
  130. add_action( 'init', array( $this, 'init' ), 0 ); 
  131. add_action( 'init', array( 'WC_Shortcodes', 'init' ) ); 
  132. add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) ); 
  133. add_action( 'init', array( $this, 'wpdb_table_fix' ), 0 ); 
  134. add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 ); 
  135.  
  136. /** 
  137. * Define WC Constants. 
  138. */ 
  139. private function define_constants() { 
  140. $upload_dir = wp_upload_dir(); 
  141.  
  142. $this->define( 'WC_PLUGIN_FILE', __FILE__ ); 
  143. $this->define( 'WC_ABSPATH', dirname( __FILE__ ) . '/' ); 
  144. $this->define( 'WC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 
  145. $this->define( 'WC_VERSION', $this->version ); 
  146. $this->define( 'WOOCOMMERCE_VERSION', $this->version ); 
  147. $this->define( 'WC_ROUNDING_PRECISION', 4 ); 
  148. $this->define( 'WC_DISCOUNT_ROUNDING_MODE', 2 ); 
  149. $this->define( 'WC_TAX_ROUNDING_MODE', 'yes' === get_option( 'woocommerce_prices_include_tax', 'no' ) ? 2 : 1 ); 
  150. $this->define( 'WC_DELIMITER', '|' ); 
  151. $this->define( 'WC_LOG_DIR', $upload_dir['basedir'] . '/wc-logs/' ); 
  152. $this->define( 'WC_SESSION_CACHE_GROUP', 'wc_session_id' ); 
  153. $this->define( 'WC_TEMPLATE_DEBUG_MODE', false ); 
  154.  
  155. /** 
  156. * Define constant if not already set. 
  157. * @param string $name 
  158. * @param string|bool $value 
  159. */ 
  160. private function define( $name, $value ) { 
  161. if ( ! defined( $name ) ) { 
  162. define( $name, $value ); 
  163.  
  164. /** 
  165. * What type of request is this? 
  166. * @param string $type admin, ajax, cron or frontend. 
  167. * @return bool 
  168. */ 
  169. private function is_request( $type ) { 
  170. switch ( $type ) { 
  171. case 'admin' : 
  172. return is_admin(); 
  173. case 'ajax' : 
  174. return defined( 'DOING_AJAX' ); 
  175. case 'cron' : 
  176. return defined( 'DOING_CRON' ); 
  177. case 'frontend' : 
  178. return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); 
  179.  
  180. /** 
  181. * Check the active theme. 
  182. * @since 2.6.9 
  183. * @param string $theme Theme slug to check 
  184. * @return bool 
  185. */ 
  186. private function is_active_theme( $theme ) { 
  187. return get_template() === $theme; 
  188.  
  189. /** 
  190. * Include required core files used in admin and on the frontend. 
  191. */ 
  192. public function includes() { 
  193. /** 
  194. * Class autoloader. 
  195. */ 
  196. include_once( WC_ABSPATH . 'includes/class-wc-autoloader.php' ); 
  197.  
  198. /** 
  199. * Interfaces. 
  200. */ 
  201. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-abstract-order-data-store-interface.php' ); 
  202. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-coupon-data-store-interface.php' ); 
  203. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-customer-data-store-interface.php' ); 
  204. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-customer-download-data-store-interface.php' ); 
  205. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-object-data-store-interface.php' ); 
  206. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-data-store-interface.php' ); 
  207. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-item-data-store-interface.php' ); 
  208. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-item-product-data-store-interface.php' ); 
  209. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-item-type-data-store-interface.php' ); 
  210. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-refund-data-store-interface.php' ); 
  211. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-payment-token-data-store-interface.php' ); 
  212. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-product-data-store-interface.php' ); 
  213. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-product-variable-data-store-interface.php' ); 
  214. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-shipping-zone-data-store-interface.php' ); 
  215. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-logger-interface.php' ); 
  216. include_once( WC_ABSPATH . 'includes/interfaces/class-wc-log-handler-interface.php' ); 
  217.  
  218. /** 
  219. * Abstract classes. 
  220. */ 
  221. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php' ); // WC_Data for CRUD 
  222. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-token.php' ); // Payment Tokens 
  223. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-product.php' ); // Products 
  224. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-order.php' ); // Orders 
  225. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations) 
  226. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method 
  227. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway 
  228. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service 
  229. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-log-handler.php' ); 
  230. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-deprecated-hooks.php' ); 
  231. include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-session.php' ); 
  232.  
  233. /** 
  234. * Core classes. 
  235. */ 
  236. include_once( WC_ABSPATH . 'includes/wc-core-functions.php' ); 
  237. include_once( WC_ABSPATH . 'includes/class-wc-datetime.php' ); 
  238. include_once( WC_ABSPATH . 'includes/class-wc-post-types.php' ); // Registers post types 
  239. include_once( WC_ABSPATH . 'includes/class-wc-install.php' ); 
  240. include_once( WC_ABSPATH . 'includes/class-wc-geolocation.php' ); 
  241. include_once( WC_ABSPATH . 'includes/class-wc-download-handler.php' ); 
  242. include_once( WC_ABSPATH . 'includes/class-wc-comments.php' ); 
  243. include_once( WC_ABSPATH . 'includes/class-wc-post-data.php' ); 
  244. include_once( WC_ABSPATH . 'includes/class-wc-ajax.php' ); 
  245. include_once( WC_ABSPATH . 'includes/class-wc-emails.php' ); 
  246. include_once( WC_ABSPATH . 'includes/class-wc-data-exception.php' ); 
  247. include_once( WC_ABSPATH . 'includes/class-wc-query.php' ); 
  248. include_once( WC_ABSPATH . 'includes/class-wc-order-factory.php' ); // Order factory 
  249. include_once( WC_ABSPATH . 'includes/class-wc-product-factory.php' ); // Product factory 
  250. include_once( WC_ABSPATH . 'includes/class-wc-payment-tokens.php' ); // Payment tokens controller 
  251. include_once( WC_ABSPATH . 'includes/class-wc-shipping-zone.php' ); 
  252. include_once( WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-cc.php' ); // CC Payment Gateway 
  253. include_once( WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-echeck.php' ); // eCheck Payment Gateway 
  254. include_once( WC_ABSPATH . 'includes/class-wc-countries.php' ); // Defines countries and states 
  255. include_once( WC_ABSPATH . 'includes/class-wc-integrations.php' ); // Loads integrations 
  256. include_once( WC_ABSPATH . 'includes/class-wc-cache-helper.php' ); // Cache Helper 
  257. include_once( WC_ABSPATH . 'includes/class-wc-https.php' ); // https Helper 
  258. include_once( WC_ABSPATH . 'includes/class-wc-deprecated-action-hooks.php' ); 
  259. include_once( WC_ABSPATH . 'includes/class-wc-deprecated-filter-hooks.php' ); 
  260. include_once( WC_ABSPATH . 'includes/class-wc-background-emailer.php' ); 
  261.  
  262. /** 
  263. * Data stores - used to store and retrieve CRUD object data from the database. 
  264. */ 
  265. include_once( WC_ABSPATH . 'includes/class-wc-data-store.php' ); 
  266. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-data-store-wp.php' ); 
  267. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-coupon-data-store-cpt.php' ); 
  268. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-data-store-cpt.php' ); 
  269. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-grouped-data-store-cpt.php' ); 
  270. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-variable-data-store-cpt.php' ); 
  271. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-variation-data-store-cpt.php' ); 
  272. include_once( WC_ABSPATH . 'includes/data-stores/abstract-wc-order-item-type-data-store.php' ); 
  273. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-data-store.php' ); 
  274. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-coupon-data-store.php' ); 
  275. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-fee-data-store.php' ); 
  276. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-product-store.php' ); 
  277. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-shipping-data-store.php' ); 
  278. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-tax-data-store.php' ); 
  279. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-payment-token-data-store.php' ); 
  280. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store.php' ); 
  281. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store-session.php' ); 
  282. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-customer-download-data-store.php' ); 
  283. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-shipping-zone-data-store.php' ); 
  284. include_once( WC_ABSPATH . 'includes/data-stores/abstract-wc-order-data-store-cpt.php' ); 
  285. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-data-store-cpt.php' ); 
  286. include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-refund-data-store-cpt.php' ); 
  287.  
  288. /** 
  289. * REST API. 
  290. */ 
  291. include_once( WC_ABSPATH . 'includes/class-wc-legacy-api.php' ); 
  292. include_once( WC_ABSPATH . 'includes/class-wc-api.php' ); // API Class 
  293. include_once( WC_ABSPATH . 'includes/class-wc-auth.php' ); // Auth Class 
  294. include_once( WC_ABSPATH . 'includes/class-wc-register-wp-admin-settings.php' ); 
  295.  
  296. if ( defined( 'WP_CLI' ) && WP_CLI ) { 
  297. include_once( WC_ABSPATH . 'includes/class-wc-cli.php' ); 
  298.  
  299. if ( $this->is_request( 'admin' ) ) { 
  300. include_once( WC_ABSPATH . 'includes/admin/class-wc-admin.php' ); 
  301.  
  302. if ( $this->is_request( 'frontend' ) ) { 
  303. $this->frontend_includes(); 
  304.  
  305. if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) { 
  306. include_once( WC_ABSPATH . 'includes/class-wc-session-handler.php' ); 
  307.  
  308. if ( $this->is_request( 'cron' ) && 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) { 
  309. include_once( WC_ABSPATH . 'includes/class-wc-tracker.php' ); 
  310.  
  311. $this->query = new WC_Query(); 
  312. $this->api = new WC_API(); 
  313.  
  314. /** 
  315. * Include required frontend files. 
  316. */ 
  317. public function frontend_includes() { 
  318. include_once( WC_ABSPATH . 'includes/wc-cart-functions.php' ); 
  319. include_once( WC_ABSPATH . 'includes/wc-notice-functions.php' ); 
  320. include_once( WC_ABSPATH . 'includes/wc-template-hooks.php' ); 
  321. include_once( WC_ABSPATH . 'includes/class-wc-template-loader.php' ); // Template Loader 
  322. include_once( WC_ABSPATH . 'includes/class-wc-frontend-scripts.php' ); // Frontend Scripts 
  323. include_once( WC_ABSPATH . 'includes/class-wc-form-handler.php' ); // Form Handlers 
  324. include_once( WC_ABSPATH . 'includes/class-wc-cart.php' ); // The main cart class 
  325. include_once( WC_ABSPATH . 'includes/class-wc-tax.php' ); // Tax class 
  326. include_once( WC_ABSPATH . 'includes/class-wc-shipping-zones.php' ); // Shipping Zones class 
  327. include_once( WC_ABSPATH . 'includes/class-wc-customer.php' ); // Customer class 
  328. include_once( WC_ABSPATH . 'includes/class-wc-shortcodes.php' ); // Shortcodes class 
  329. include_once( WC_ABSPATH . 'includes/class-wc-embed.php' ); // Embeds 
  330. include_once( WC_ABSPATH . 'includes/class-wc-structured-data.php' ); // Structured Data class 
  331.  
  332. if ( $this->is_active_theme( 'twentyseventeen' ) ) { 
  333. include_once( WC_ABSPATH . 'includes/theme-support/class-wc-twenty-seventeen.php' ); 
  334.  
  335. /** 
  336. * Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes. 
  337. */ 
  338. public function include_template_functions() { 
  339. include_once( WC_ABSPATH . 'includes/wc-template-functions.php' ); 
  340.  
  341. /** 
  342. * Init WooCommerce when WordPress Initialises. 
  343. */ 
  344. public function init() { 
  345. // Before init action. 
  346. do_action( 'before_woocommerce_init' ); 
  347.  
  348. // Set up localisation. 
  349. $this->load_plugin_textdomain(); 
  350.  
  351. // Load class instances. 
  352. $this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances 
  353. $this->order_factory = new WC_Order_Factory(); // Order Factory to create new order instances 
  354. $this->countries = new WC_Countries(); // Countries class 
  355. $this->integrations = new WC_Integrations(); // Integrations class 
  356. $this->structured_data = new WC_Structured_Data(); // Structured Data class, generates and handles structured data 
  357. $this->deprecated_hook_handlers['actions'] = new WC_Deprecated_Action_Hooks(); 
  358. $this->deprecated_hook_handlers['filters'] = new WC_Deprecated_Filter_Hooks(); 
  359.  
  360. // Session class, handles session data for users - can be overwritten if custom handler is needed. 
  361. if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) { 
  362. $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); 
  363. $this->session = new $session_class(); 
  364.  
  365. // Classes/actions loaded for the frontend and for ajax requests. 
  366. if ( $this->is_request( 'frontend' ) ) { 
  367. $this->cart = new WC_Cart(); // Cart class, stores the cart contents 
  368. $this->customer = new WC_Customer( get_current_user_id(), true ); // Customer class, handles data such as customer location 
  369. add_action( 'shutdown', array( $this->customer, 'save' ), 10 ); // Customer should be saved during shutdown. 
  370.  
  371. $this->load_webhooks(); 
  372.  
  373. // Init action. 
  374. do_action( 'woocommerce_init' ); 
  375.  
  376. /** 
  377. * Load Localisation files. 
  378. * Note: the first-loaded translation file overrides any following ones if the same translation is present. 
  379. * Locales found in: 
  380. * - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo 
  381. * - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo 
  382. */ 
  383. public function load_plugin_textdomain() { 
  384. $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); 
  385. $locale = apply_filters( 'plugin_locale', $locale, 'woocommerce' ); 
  386.  
  387. load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-' . $locale . '.mo' ); 
  388. load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages' ); 
  389.  
  390. /** 
  391. * Ensure theme and server variable compatibility and setup image sizes. 
  392. */ 
  393. public function setup_environment() { 
  394. /** 
  395. * @deprecated 2.2 Use WC()->template_path() 
  396. */ 
  397. $this->define( 'WC_TEMPLATE_PATH', $this->template_path() ); 
  398.  
  399. $this->add_thumbnail_support(); 
  400. $this->add_image_sizes(); 
  401.  
  402. /** 
  403. * Ensure post thumbnail support is turned on. 
  404. */ 
  405. private function add_thumbnail_support() { 
  406. if ( ! current_theme_supports( 'post-thumbnails' ) ) { 
  407. add_theme_support( 'post-thumbnails' ); 
  408. add_post_type_support( 'product', 'thumbnail' ); 
  409.  
  410. /** 
  411. * Add WC Image sizes to WP. 
  412. * @since 2.3 
  413. */ 
  414. private function add_image_sizes() { 
  415. $shop_thumbnail = wc_get_image_size( 'shop_thumbnail' ); 
  416. $shop_catalog = wc_get_image_size( 'shop_catalog' ); 
  417. $shop_single = wc_get_image_size( 'shop_single' ); 
  418.  
  419. add_image_size( 'shop_thumbnail', $shop_thumbnail['width'], $shop_thumbnail['height'], $shop_thumbnail['crop'] ); 
  420. add_image_size( 'shop_catalog', $shop_catalog['width'], $shop_catalog['height'], $shop_catalog['crop'] ); 
  421. add_image_size( 'shop_single', $shop_single['width'], $shop_single['height'], $shop_single['crop'] ); 
  422.  
  423. /** 
  424. * Get the plugin url. 
  425. * @return string 
  426. */ 
  427. public function plugin_url() { 
  428. return untrailingslashit( plugins_url( '/', __FILE__ ) ); 
  429.  
  430. /** 
  431. * Get the plugin path. 
  432. * @return string 
  433. */ 
  434. public function plugin_path() { 
  435. return untrailingslashit( plugin_dir_path( __FILE__ ) ); 
  436.  
  437. /** 
  438. * Get the template path. 
  439. * @return string 
  440. */ 
  441. public function template_path() { 
  442. return apply_filters( 'woocommerce_template_path', 'woocommerce/' ); 
  443.  
  444. /** 
  445. * Get Ajax URL. 
  446. * @return string 
  447. */ 
  448. public function ajax_url() { 
  449. return admin_url( 'admin-ajax.php', 'relative' ); 
  450.  
  451. /** 
  452. * Return the WC API URL for a given request. 
  453. * @param string $request 
  454. * @param mixed $ssl (default: null) 
  455. * @return string 
  456. */ 
  457. public function api_request_url( $request, $ssl = null ) { 
  458. if ( is_null( $ssl ) ) { 
  459. $scheme = parse_url( home_url(), PHP_URL_SCHEME ); 
  460. } elseif ( $ssl ) { 
  461. $scheme = 'https'; 
  462. } else { 
  463. $scheme = 'http'; 
  464.  
  465. if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) { 
  466. $api_request_url = trailingslashit( home_url( '/index.php/wc-api/' . $request, $scheme ) ); 
  467. } elseif ( get_option( 'permalink_structure' ) ) { 
  468. $api_request_url = trailingslashit( home_url( '/wc-api/' . $request, $scheme ) ); 
  469. } else { 
  470. $api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) ); 
  471.  
  472. return esc_url_raw( apply_filters( 'woocommerce_api_request_url', $api_request_url, $request, $ssl ) ); 
  473.  
  474. /** 
  475. * Load & enqueue active webhooks. 
  476. * @since 2.2 
  477. */ 
  478. private function load_webhooks() { 
  479.  
  480. if ( ! is_blog_installed() ) { 
  481. return; 
  482.  
  483. if ( false === ( $webhooks = get_transient( 'woocommerce_webhook_ids' ) ) ) { 
  484. $webhooks = get_posts( array( 
  485. 'fields' => 'ids',  
  486. 'post_type' => 'shop_webhook',  
  487. 'post_status' => 'publish',  
  488. 'posts_per_page' => -1,  
  489. ) ); 
  490. set_transient( 'woocommerce_webhook_ids', $webhooks ); 
  491. foreach ( $webhooks as $webhook_id ) { 
  492. $webhook = new WC_Webhook( $webhook_id ); 
  493. $webhook->enqueue(); 
  494.  
  495. /** 
  496. * WooCommerce Payment Token Meta API and Term/Order item Meta - set table names. 
  497. */ 
  498. public function wpdb_table_fix() { 
  499. global $wpdb; 
  500. $wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta'; 
  501. $wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta'; 
  502. $wpdb->tables[] = 'woocommerce_payment_tokenmeta'; 
  503. $wpdb->tables[] = 'woocommerce_order_itemmeta'; 
  504.  
  505. if ( get_option( 'db_version' ) < 34370 ) { 
  506. $wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta'; 
  507. $wpdb->tables[] = 'woocommerce_termmeta'; 
  508.  
  509. /** 
  510. * Get Checkout Class. 
  511. * @return WC_Checkout 
  512. */ 
  513. public function checkout() { 
  514. return WC_Checkout::instance(); 
  515.  
  516. /** 
  517. * Get gateways class. 
  518. * @return WC_Payment_Gateways 
  519. */ 
  520. public function payment_gateways() { 
  521. return WC_Payment_Gateways::instance(); 
  522.  
  523. /** 
  524. * Get shipping class. 
  525. * @return WC_Shipping 
  526. */ 
  527. public function shipping() { 
  528. return WC_Shipping::instance(); 
  529.  
  530. /** 
  531. * Email Class. 
  532. * @return WC_Emails 
  533. */ 
  534. public function mailer() { 
  535. return WC_Emails::instance();