2011-08-10 17:11:11 +00:00
|
|
|
<?php
|
2012-03-20 13:22:35 +00:00
|
|
|
/**
|
|
|
|
* Plugin Name: WooCommerce
|
2016-07-05 22:52:16 +00:00
|
|
|
* Plugin URI: https://woocommerce.com/
|
2012-03-20 13:22:35 +00:00
|
|
|
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
|
2017-06-14 19:09:00 +00:00
|
|
|
* Version: 3.2.0-dev
|
2017-02-09 17:08:39 +00:00
|
|
|
* Author: Automattic
|
2016-09-27 15:44:48 +00:00
|
|
|
* Author URI: https://woocommerce.com
|
2016-06-14 13:38:43 +00:00
|
|
|
* Requires at least: 4.4
|
2016-12-15 16:44:58 +00:00
|
|
|
* Tested up to: 4.7
|
2012-08-07 08:38:08 +00:00
|
|
|
*
|
2012-03-20 13:22:35 +00:00
|
|
|
* Text Domain: woocommerce
|
2012-12-28 10:54:02 +00:00
|
|
|
* Domain Path: /i18n/languages/
|
2012-08-07 08:38:08 +00:00
|
|
|
*
|
2012-03-20 13:22:35 +00:00
|
|
|
* @package WooCommerce
|
|
|
|
* @category Core
|
2017-02-09 17:08:39 +00:00
|
|
|
* @author Automattic
|
2012-03-20 13:22:35 +00:00
|
|
|
*/
|
2014-01-08 15:30:06 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2015-10-29 14:06:28 +00:00
|
|
|
exit; // Exit if accessed directly.
|
2014-01-08 15:30:06 +00:00
|
|
|
}
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
if ( ! class_exists( 'WooCommerce' ) ) :
|
2013-08-09 16:11:15 +00:00
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Main WooCommerce Class.
|
2013-06-11 14:21:14 +00:00
|
|
|
*
|
|
|
|
* @class WooCommerce
|
2017-06-14 19:09:00 +00:00
|
|
|
* @version 3.2.0
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
|
|
|
final class WooCommerce {
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* WooCommerce version.
|
|
|
|
*
|
2013-06-11 14:21:14 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2017-06-14 19:09:00 +00:00
|
|
|
public $version = '3.2.0';
|
2013-06-11 14:21:14 +00:00
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* The single instance of the class.
|
|
|
|
*
|
|
|
|
* @var WooCommerce
|
2013-09-12 13:41:02 +00:00
|
|
|
* @since 2.1
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
2013-09-12 13:41:02 +00:00
|
|
|
protected static $_instance = null;
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2013-09-26 12:11:33 +00:00
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Session instance.
|
|
|
|
*
|
2017-03-15 07:39:39 +00:00
|
|
|
* @var WC_Session|WC_Session_Handler
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $session = null;
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Query instance.
|
|
|
|
*
|
|
|
|
* @var WC_Query
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $query = null;
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Product factory instance.
|
|
|
|
*
|
|
|
|
* @var WC_Product_Factory
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $product_factory = null;
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Countries instance.
|
|
|
|
*
|
|
|
|
* @var WC_Countries
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $countries = null;
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Integrations instance.
|
|
|
|
*
|
|
|
|
* @var WC_Integrations
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $integrations = null;
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Cart instance.
|
|
|
|
*
|
|
|
|
* @var WC_Cart
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $cart = null;
|
|
|
|
|
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Customer instance.
|
|
|
|
*
|
|
|
|
* @var WC_Customer
|
2013-09-26 12:11:33 +00:00
|
|
|
*/
|
|
|
|
public $customer = null;
|
|
|
|
|
2014-07-03 11:38:55 +00:00
|
|
|
/**
|
2016-01-06 16:15:20 +00:00
|
|
|
* Order factory instance.
|
|
|
|
*
|
|
|
|
* @var WC_Order_Factory
|
2014-08-31 05:41:40 +00:00
|
|
|
*/
|
|
|
|
public $order_factory = null;
|
2014-07-03 11:38:55 +00:00
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
2016-08-10 22:23:26 +00:00
|
|
|
* Structured data instance.
|
|
|
|
*
|
|
|
|
* @var WC_Structured_Data
|
|
|
|
*/
|
|
|
|
public $structured_data = null;
|
2016-09-21 14:37:54 +00:00
|
|
|
|
2017-02-15 19:34:14 +00:00
|
|
|
/**
|
|
|
|
* Array of deprecated hook handlers.
|
|
|
|
*
|
|
|
|
* @var array of WC_Deprecated_Hooks
|
|
|
|
*/
|
|
|
|
public $deprecated_hook_handlers = array();
|
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Main WooCommerce Instance.
|
2013-06-11 14:21:14 +00:00
|
|
|
*
|
|
|
|
* Ensures only one instance of WooCommerce is loaded or can be loaded.
|
|
|
|
*
|
|
|
|
* @since 2.1
|
|
|
|
* @static
|
|
|
|
* @see WC()
|
2015-10-29 14:06:28 +00:00
|
|
|
* @return WooCommerce - Main instance.
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
|
|
|
public static function instance() {
|
2013-12-08 21:25:57 +00:00
|
|
|
if ( is_null( self::$_instance ) ) {
|
2013-06-11 14:21:14 +00:00
|
|
|
self::$_instance = new self();
|
2013-12-08 21:25:57 +00:00
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
return self::$_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cloning is forbidden.
|
|
|
|
* @since 2.1
|
|
|
|
*/
|
|
|
|
public function __clone() {
|
2016-11-23 16:15:00 +00:00
|
|
|
wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unserializing instances of this class is forbidden.
|
|
|
|
* @since 2.1
|
|
|
|
*/
|
|
|
|
public function __wakeup() {
|
2016-11-23 16:15:00 +00:00
|
|
|
wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woocommerce' ), '2.1' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 00:02:56 +00:00
|
|
|
/**
|
|
|
|
* Auto-load in-accessible properties on demand.
|
|
|
|
* @param mixed $key
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __get( $key ) {
|
|
|
|
if ( in_array( $key, array( 'payment_gateways', 'shipping', 'mailer', 'checkout' ) ) ) {
|
|
|
|
return $this->$key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce Constructor.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2013-10-24 18:36:22 +00:00
|
|
|
$this->define_constants();
|
2015-01-28 18:01:30 +00:00
|
|
|
$this->includes();
|
2015-01-28 17:01:52 +00:00
|
|
|
$this->init_hooks();
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2015-01-28 18:01:30 +00:00
|
|
|
do_action( 'woocommerce_loaded' );
|
2015-01-28 17:50:58 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 17:01:52 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Hook into actions and filters.
|
2015-01-28 17:01:52 +00:00
|
|
|
* @since 2.3
|
|
|
|
*/
|
2015-01-28 17:50:58 +00:00
|
|
|
private function init_hooks() {
|
|
|
|
register_activation_hook( __FILE__, array( 'WC_Install', 'install' ) );
|
2014-07-31 06:47:55 +00:00
|
|
|
add_action( 'after_setup_theme', array( $this, 'setup_environment' ) );
|
|
|
|
add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 );
|
2013-06-11 14:21:14 +00:00
|
|
|
add_action( 'init', array( $this, 'init' ), 0 );
|
2013-10-23 11:55:40 +00:00
|
|
|
add_action( 'init', array( 'WC_Shortcodes', 'init' ) );
|
2014-11-26 00:02:56 +00:00
|
|
|
add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
|
2016-06-06 18:29:47 +00:00
|
|
|
add_action( 'init', array( $this, 'wpdb_table_fix' ), 0 );
|
|
|
|
add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 );
|
2015-01-28 17:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Define WC Constants.
|
2015-01-28 17:01:52 +00:00
|
|
|
*/
|
2015-01-28 17:50:58 +00:00
|
|
|
private function define_constants() {
|
|
|
|
$upload_dir = wp_upload_dir();
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2015-01-28 17:50:58 +00:00
|
|
|
$this->define( 'WC_PLUGIN_FILE', __FILE__ );
|
2016-07-27 10:58:43 +00:00
|
|
|
$this->define( 'WC_ABSPATH', dirname( __FILE__ ) . '/' );
|
2015-01-28 17:50:58 +00:00
|
|
|
$this->define( 'WC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
|
|
|
$this->define( 'WC_VERSION', $this->version );
|
|
|
|
$this->define( 'WOOCOMMERCE_VERSION', $this->version );
|
|
|
|
$this->define( 'WC_ROUNDING_PRECISION', 4 );
|
2015-04-10 09:28:30 +00:00
|
|
|
$this->define( 'WC_DISCOUNT_ROUNDING_MODE', 2 );
|
2015-01-28 17:50:58 +00:00
|
|
|
$this->define( 'WC_TAX_ROUNDING_MODE', 'yes' === get_option( 'woocommerce_prices_include_tax', 'no' ) ? 2 : 1 );
|
|
|
|
$this->define( 'WC_DELIMITER', '|' );
|
|
|
|
$this->define( 'WC_LOG_DIR', $upload_dir['basedir'] . '/wc-logs/' );
|
2015-10-07 13:47:29 +00:00
|
|
|
$this->define( 'WC_SESSION_CACHE_GROUP', 'wc_session_id' );
|
2016-08-24 15:46:07 +00:00
|
|
|
$this->define( 'WC_TEMPLATE_DEBUG_MODE', false );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 22:50:13 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Define constant if not already set.
|
2015-11-03 12:28:01 +00:00
|
|
|
*
|
2014-11-19 22:50:13 +00:00
|
|
|
* @param string $name
|
2014-11-25 23:21:39 +00:00
|
|
|
* @param string|bool $value
|
2014-11-19 22:50:13 +00:00
|
|
|
*/
|
|
|
|
private function define( $name, $value ) {
|
|
|
|
if ( ! defined( $name ) ) {
|
|
|
|
define( $name, $value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* What type of request is this?
|
2015-11-03 12:28:01 +00:00
|
|
|
*
|
2016-05-18 09:42:48 +00:00
|
|
|
* @param string $type admin, ajax, cron or frontend.
|
2015-01-23 18:39:49 +00:00
|
|
|
* @return bool
|
2014-11-25 23:21:39 +00:00
|
|
|
*/
|
|
|
|
private function is_request( $type ) {
|
|
|
|
switch ( $type ) {
|
|
|
|
case 'admin' :
|
|
|
|
return is_admin();
|
|
|
|
case 'ajax' :
|
|
|
|
return defined( 'DOING_AJAX' );
|
2015-01-23 16:36:52 +00:00
|
|
|
case 'cron' :
|
|
|
|
return defined( 'DOING_CRON' );
|
2014-11-25 23:21:39 +00:00
|
|
|
case 'frontend' :
|
2015-01-23 11:09:03 +00:00
|
|
|
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
|
2014-11-25 23:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 12:14:00 +00:00
|
|
|
/**
|
2016-12-07 12:45:54 +00:00
|
|
|
* Check the active theme.
|
2016-12-06 12:14:00 +00:00
|
|
|
*
|
2016-12-07 12:45:54 +00:00
|
|
|
* @since 2.6.9
|
2016-12-06 12:14:00 +00:00
|
|
|
* @param string $theme Theme slug to check
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function is_active_theme( $theme ) {
|
2016-12-15 17:11:08 +00:00
|
|
|
return get_template() === $theme;
|
2016-12-06 12:14:00 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
|
|
|
* Include required core files used in admin and on the frontend.
|
|
|
|
*/
|
2015-01-28 17:50:58 +00:00
|
|
|
public function includes() {
|
2017-02-16 11:46:01 +00:00
|
|
|
/**
|
|
|
|
* Class autoloader.
|
|
|
|
*/
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-autoloader.php' );
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2017-02-16 11:46:01 +00:00
|
|
|
/**
|
|
|
|
* Interfaces.
|
|
|
|
*/
|
2017-01-16 21:33:21 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-abstract-order-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-coupon-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-customer-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-customer-download-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-object-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-item-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-item-product-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-item-type-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-order-refund-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-payment-token-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-product-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-product-variable-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-shipping-zone-data-store-interface.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-logger-interface.php' );
|
2017-01-24 13:10:00 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/interfaces/class-wc-log-handler-interface.php' );
|
2017-02-16 11:46:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract classes.
|
|
|
|
*/
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php' ); // WC_Data for CRUD
|
2017-04-24 18:33:17 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-object-query.php' ); // WC_Object_Query for CRUD
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-token.php' ); // Payment Tokens
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-product.php' ); // Products
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-order.php' ); // Orders
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service
|
2016-12-11 17:24:59 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-log-handler.php' );
|
2017-02-16 11:46:01 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-deprecated-hooks.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-session.php' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core classes.
|
|
|
|
*/
|
|
|
|
include_once( WC_ABSPATH . 'includes/wc-core-functions.php' );
|
2017-03-08 16:51:55 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-datetime.php' );
|
2017-02-16 11:46:01 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-post-types.php' ); // Registers post types
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-install.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-geolocation.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-download-handler.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-comments.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-post-data.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-ajax.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-emails.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-data-exception.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-query.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-order-factory.php' ); // Order factory
|
2017-04-24 23:28:13 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-order-query.php' ); // Order query
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-product-factory.php' ); // Product factory
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-payment-tokens.php' ); // Payment tokens controller
|
2016-11-15 21:53:11 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-shipping-zone.php' );
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-cc.php' ); // CC Payment Gateway
|
|
|
|
include_once( WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-echeck.php' ); // eCheck Payment Gateway
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-countries.php' ); // Defines countries and states
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-integrations.php' ); // Loads integrations
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-cache-helper.php' ); // Cache Helper
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-https.php' ); // https Helper
|
2017-02-16 11:46:01 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-deprecated-action-hooks.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-deprecated-filter-hooks.php' );
|
2017-04-06 12:46:07 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-background-emailer.php' );
|
2017-02-16 11:46:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data stores - used to store and retrieve CRUD object data from the database.
|
|
|
|
*/
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-data-store.php' );
|
2016-11-21 23:48:49 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-data-store-wp.php' );
|
2016-11-09 12:21:18 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-coupon-data-store-cpt.php' );
|
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-data-store-cpt.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-grouped-data-store-cpt.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-variable-data-store-cpt.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-variation-data-store-cpt.php' );
|
2016-11-21 19:38:07 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/abstract-wc-order-item-type-data-store.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-data-store.php' );
|
2016-11-17 21:30:34 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-coupon-data-store.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-fee-data-store.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-product-store.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-shipping-data-store.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-item-tax-data-store.php' );
|
2016-11-16 11:18:47 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-payment-token-data-store.php' );
|
2016-11-14 18:18:08 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store-session.php' );
|
2016-11-18 14:07:21 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-customer-download-data-store.php' );
|
2016-11-16 11:18:47 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-shipping-zone-data-store.php' );
|
2016-11-17 14:37:29 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/abstract-wc-order-data-store-cpt.php' );
|
2016-11-17 10:53:22 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-data-store-cpt.php' );
|
2016-11-17 16:53:13 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-refund-data-store-cpt.php' );
|
2016-11-08 09:39:47 +00:00
|
|
|
|
2017-02-16 11:46:01 +00:00
|
|
|
/**
|
|
|
|
* REST API.
|
|
|
|
*/
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-legacy-api.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-api.php' ); // API Class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-auth.php' ); // Auth Class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-register-wp-admin-settings.php' );
|
|
|
|
|
2016-12-08 18:59:07 +00:00
|
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
2017-02-16 11:46:01 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-cli.php' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->is_request( 'admin' ) ) {
|
|
|
|
include_once( WC_ABSPATH . 'includes/admin/class-wc-admin.php' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->is_request( 'frontend' ) ) {
|
|
|
|
$this->frontend_includes();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-session-handler.php' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->is_request( 'cron' ) && 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) {
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-tracker.php' );
|
2016-12-08 18:59:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 10:03:16 +00:00
|
|
|
$this->query = new WC_Query();
|
|
|
|
$this->api = new WC_API();
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include required frontend files.
|
|
|
|
*/
|
|
|
|
public function frontend_includes() {
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/wc-cart-functions.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/wc-notice-functions.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/wc-template-hooks.php' );
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-template-loader.php' ); // Template Loader
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-frontend-scripts.php' ); // Frontend Scripts
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-form-handler.php' ); // Form Handlers
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-cart.php' ); // The main cart class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-tax.php' ); // Tax class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-shipping-zones.php' ); // Shipping Zones class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-customer.php' ); // Customer class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-shortcodes.php' ); // Shortcodes class
|
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-embed.php' ); // Embeds
|
2016-08-11 09:17:14 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/class-wc-structured-data.php' ); // Structured Data class
|
2016-12-06 12:14:00 +00:00
|
|
|
|
|
|
|
if ( $this->is_active_theme( 'twentyseventeen' ) ) {
|
2016-12-07 12:45:54 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/theme-support/class-wc-twenty-seventeen.php' );
|
2016-12-06 12:14:00 +00:00
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes.
|
|
|
|
*/
|
|
|
|
public function include_template_functions() {
|
2016-07-27 10:58:43 +00:00
|
|
|
include_once( WC_ABSPATH . 'includes/wc-template-functions.php' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init WooCommerce when WordPress Initialises.
|
|
|
|
*/
|
|
|
|
public function init() {
|
2015-10-29 14:06:28 +00:00
|
|
|
// Before init action.
|
2013-06-11 14:21:14 +00:00
|
|
|
do_action( 'before_woocommerce_init' );
|
|
|
|
|
2015-10-29 14:06:28 +00:00
|
|
|
// Set up localisation.
|
2013-06-11 14:21:14 +00:00
|
|
|
$this->load_plugin_textdomain();
|
|
|
|
|
2015-10-29 14:06:28 +00:00
|
|
|
// Load class instances.
|
2017-02-16 11:46:01 +00:00
|
|
|
$this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances
|
|
|
|
$this->order_factory = new WC_Order_Factory(); // Order Factory to create new order instances
|
|
|
|
$this->countries = new WC_Countries(); // Countries class
|
|
|
|
$this->integrations = new WC_Integrations(); // Integrations class
|
|
|
|
$this->structured_data = new WC_Structured_Data(); // Structured Data class, generates and handles structured data
|
|
|
|
$this->deprecated_hook_handlers['actions'] = new WC_Deprecated_Action_Hooks();
|
|
|
|
$this->deprecated_hook_handlers['filters'] = new WC_Deprecated_Filter_Hooks();
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2015-10-29 14:06:28 +00:00
|
|
|
// Session class, handles session data for users - can be overwritten if custom handler is needed.
|
2015-07-16 16:32:31 +00:00
|
|
|
if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {
|
|
|
|
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
|
|
|
|
$this->session = new $session_class();
|
|
|
|
}
|
|
|
|
|
2015-10-29 14:06:28 +00:00
|
|
|
// Classes/actions loaded for the frontend and for ajax requests.
|
2014-11-25 23:21:39 +00:00
|
|
|
if ( $this->is_request( 'frontend' ) ) {
|
2016-08-15 20:05:06 +00:00
|
|
|
$this->cart = new WC_Cart(); // Cart class, stores the cart contents
|
2016-11-14 18:18:08 +00:00
|
|
|
$this->customer = new WC_Customer( get_current_user_id(), true ); // Customer class, handles data such as customer location
|
|
|
|
add_action( 'shutdown', array( $this->customer, 'save' ), 10 ); // Customer should be saved during shutdown.
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 20:27:50 +00:00
|
|
|
$this->load_webhooks();
|
|
|
|
|
2015-10-29 14:06:28 +00:00
|
|
|
// Init action.
|
2013-06-11 14:21:14 +00:00
|
|
|
do_action( 'woocommerce_init' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load Localisation files.
|
|
|
|
*
|
2014-11-19 16:39:26 +00:00
|
|
|
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
|
|
|
|
*
|
2015-10-06 13:27:17 +00:00
|
|
|
* Locales found in:
|
|
|
|
* - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo
|
|
|
|
* - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
|
|
|
public function load_plugin_textdomain() {
|
2017-04-17 16:34:19 +00:00
|
|
|
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
|
|
|
|
$locale = apply_filters( 'plugin_locale', $locale, 'woocommerce' );
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2017-06-05 13:18:39 +00:00
|
|
|
unload_textdomain( 'woocommerce' );
|
2014-11-19 16:39:26 +00:00
|
|
|
load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-' . $locale . '.mo' );
|
2015-10-06 13:27:17 +00:00
|
|
|
load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-31 05:41:40 +00:00
|
|
|
* Ensure theme and server variable compatibility and setup image sizes.
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
2013-09-12 13:41:02 +00:00
|
|
|
public function setup_environment() {
|
2014-06-23 15:29:15 +00:00
|
|
|
/**
|
|
|
|
* @deprecated 2.2 Use WC()->template_path()
|
|
|
|
*/
|
2014-11-19 22:50:13 +00:00
|
|
|
$this->define( 'WC_TEMPLATE_PATH', $this->template_path() );
|
2014-06-23 15:29:15 +00:00
|
|
|
|
2014-10-27 14:59:22 +00:00
|
|
|
$this->add_thumbnail_support();
|
|
|
|
$this->add_image_sizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Ensure post thumbnail support is turned on.
|
2014-10-27 14:59:22 +00:00
|
|
|
*/
|
|
|
|
private function add_thumbnail_support() {
|
2014-06-23 15:29:15 +00:00
|
|
|
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
|
2014-07-30 20:27:50 +00:00
|
|
|
add_theme_support( 'post-thumbnails' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
2014-06-23 15:29:15 +00:00
|
|
|
add_post_type_support( 'product', 'thumbnail' );
|
2014-10-27 14:59:22 +00:00
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2014-10-27 14:59:22 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Add WC Image sizes to WP.
|
2014-10-27 14:59:22 +00:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
private function add_image_sizes() {
|
2013-09-12 13:41:02 +00:00
|
|
|
$shop_thumbnail = wc_get_image_size( 'shop_thumbnail' );
|
|
|
|
$shop_catalog = wc_get_image_size( 'shop_catalog' );
|
|
|
|
$shop_single = wc_get_image_size( 'shop_single' );
|
|
|
|
|
|
|
|
add_image_size( 'shop_thumbnail', $shop_thumbnail['width'], $shop_thumbnail['height'], $shop_thumbnail['crop'] );
|
|
|
|
add_image_size( 'shop_catalog', $shop_catalog['width'], $shop_catalog['height'], $shop_catalog['crop'] );
|
|
|
|
add_image_size( 'shop_single', $shop_single['width'], $shop_single['height'], $shop_single['crop'] );
|
2014-10-27 14:59:22 +00:00
|
|
|
}
|
2013-09-12 13:41:02 +00:00
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
|
|
|
* Get the plugin url.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function plugin_url() {
|
2013-06-11 14:59:54 +00:00
|
|
|
return untrailingslashit( plugins_url( '/', __FILE__ ) );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the plugin path.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function plugin_path() {
|
2013-06-11 14:59:54 +00:00
|
|
|
return untrailingslashit( plugin_dir_path( __FILE__ ) );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
|
|
|
* Get the template path.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function template_path() {
|
2014-06-23 15:31:49 +00:00
|
|
|
return apply_filters( 'woocommerce_template_path', 'woocommerce/' );
|
2013-09-12 13:41:02 +00:00
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Ajax URL.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function ajax_url() {
|
|
|
|
return admin_url( 'admin-ajax.php', 'relative' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Return the WC API URL for a given request.
|
2013-06-11 14:21:14 +00:00
|
|
|
*
|
2014-09-07 23:37:55 +00:00
|
|
|
* @param string $request
|
2013-06-11 14:21:14 +00:00
|
|
|
* @param mixed $ssl (default: null)
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function api_request_url( $request, $ssl = null ) {
|
|
|
|
if ( is_null( $ssl ) ) {
|
2014-08-27 20:24:45 +00:00
|
|
|
$scheme = parse_url( home_url(), PHP_URL_SCHEME );
|
2013-06-11 14:21:14 +00:00
|
|
|
} elseif ( $ssl ) {
|
|
|
|
$scheme = 'https';
|
|
|
|
} else {
|
|
|
|
$scheme = 'http';
|
|
|
|
}
|
|
|
|
|
2015-01-05 16:33:09 +00:00
|
|
|
if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) {
|
|
|
|
$api_request_url = trailingslashit( home_url( '/index.php/wc-api/' . $request, $scheme ) );
|
|
|
|
} elseif ( get_option( 'permalink_structure' ) ) {
|
|
|
|
$api_request_url = trailingslashit( home_url( '/wc-api/' . $request, $scheme ) );
|
2013-08-23 19:29:24 +00:00
|
|
|
} else {
|
2015-01-05 16:33:09 +00:00
|
|
|
$api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) );
|
2013-08-23 19:29:24 +00:00
|
|
|
}
|
2015-01-05 16:33:09 +00:00
|
|
|
|
2016-01-08 15:01:55 +00:00
|
|
|
return esc_url_raw( apply_filters( 'woocommerce_api_request_url', $api_request_url, $request, $ssl ) );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 20:27:50 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Load & enqueue active webhooks.
|
2014-07-30 20:27:50 +00:00
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
2014-11-25 23:21:39 +00:00
|
|
|
private function load_webhooks() {
|
2016-11-09 11:53:39 +00:00
|
|
|
|
|
|
|
if ( ! is_blog_installed() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-23 13:28:30 +00:00
|
|
|
if ( false === ( $webhooks = get_transient( 'woocommerce_webhook_ids' ) ) ) {
|
|
|
|
$webhooks = get_posts( array(
|
|
|
|
'fields' => 'ids',
|
|
|
|
'post_type' => 'shop_webhook',
|
|
|
|
'post_status' => 'publish',
|
2016-08-27 01:46:45 +00:00
|
|
|
'posts_per_page' => -1,
|
2015-01-23 13:28:30 +00:00
|
|
|
) );
|
|
|
|
set_transient( 'woocommerce_webhook_ids', $webhooks );
|
|
|
|
}
|
|
|
|
foreach ( $webhooks as $webhook_id ) {
|
|
|
|
$webhook = new WC_Webhook( $webhook_id );
|
|
|
|
$webhook->enqueue();
|
2014-07-30 20:27:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-09 20:19:34 +00:00
|
|
|
/**
|
2016-06-06 18:29:47 +00:00
|
|
|
* WooCommerce Payment Token Meta API and Term/Order item Meta - set table names.
|
2016-02-09 20:19:34 +00:00
|
|
|
*/
|
2016-06-06 18:29:47 +00:00
|
|
|
public function wpdb_table_fix() {
|
2016-02-09 20:19:34 +00:00
|
|
|
global $wpdb;
|
2016-06-06 18:29:47 +00:00
|
|
|
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
|
|
|
|
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
|
|
|
|
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
|
|
|
|
$wpdb->tables[] = 'woocommerce_order_itemmeta';
|
2016-08-02 13:09:56 +00:00
|
|
|
|
|
|
|
if ( get_option( 'db_version' ) < 34370 ) {
|
|
|
|
$wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta';
|
|
|
|
$wpdb->tables[] = 'woocommerce_termmeta';
|
|
|
|
}
|
2016-02-09 20:19:34 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
|
|
|
* Get Checkout Class.
|
|
|
|
* @return WC_Checkout
|
|
|
|
*/
|
|
|
|
public function checkout() {
|
|
|
|
return WC_Checkout::instance();
|
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Get gateways class.
|
2013-09-12 13:41:02 +00:00
|
|
|
* @return WC_Payment_Gateways
|
|
|
|
*/
|
|
|
|
public function payment_gateways() {
|
|
|
|
return WC_Payment_Gateways::instance();
|
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Get shipping class.
|
2013-09-12 13:41:02 +00:00
|
|
|
* @return WC_Shipping
|
|
|
|
*/
|
|
|
|
public function shipping() {
|
|
|
|
return WC_Shipping::instance();
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-12 13:41:02 +00:00
|
|
|
* Email Class.
|
2014-09-07 23:37:55 +00:00
|
|
|
* @return WC_Emails
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
2013-09-12 13:41:02 +00:00
|
|
|
public function mailer() {
|
|
|
|
return WC_Emails::instance();
|
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endif;
|
|
|
|
|
|
|
|
/**
|
2015-10-29 14:06:28 +00:00
|
|
|
* Main instance of WooCommerce.
|
2015-11-03 12:28:01 +00:00
|
|
|
*
|
2013-06-11 14:21:14 +00:00
|
|
|
* Returns the main instance of WC to prevent the need to use globals.
|
|
|
|
*
|
|
|
|
* @since 2.1
|
2013-09-25 13:10:40 +00:00
|
|
|
* @return WooCommerce
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
|
|
|
function WC() {
|
|
|
|
return WooCommerce::instance();
|
|
|
|
}
|
2011-12-08 12:50:50 +00:00
|
|
|
|
2013-09-25 03:11:42 +00:00
|
|
|
// Global for backwards compatibility.
|
2013-06-13 13:36:12 +00:00
|
|
|
$GLOBALS['woocommerce'] = WC();
|