2011-08-10 17:11:11 +00:00
|
|
|
<?php
|
2012-03-20 13:22:35 +00:00
|
|
|
/**
|
|
|
|
* Plugin Name: WooCommerce
|
|
|
|
* Plugin URI: http://www.woothemes.com/woocommerce/
|
|
|
|
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
|
2015-07-15 19:40:40 +00:00
|
|
|
* Version: 2.4.0-beta-3
|
2012-03-20 13:22:35 +00:00
|
|
|
* Author: WooThemes
|
|
|
|
* Author URI: http://woothemes.com
|
2015-06-08 12:18:23 +00:00
|
|
|
* Requires at least: 4.1
|
|
|
|
* Tested up to: 4.2
|
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
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
2014-01-08 15:30:06 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2013-09-12 13:41:02 +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
|
|
|
/**
|
|
|
|
* Main WooCommerce Class
|
|
|
|
*
|
|
|
|
* @class WooCommerce
|
2015-07-15 10:31:12 +00:00
|
|
|
* @version 2.4.0
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
|
|
|
final class WooCommerce {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2015-06-16 14:10:53 +00:00
|
|
|
public $version = '2.4.0';
|
2013-06-11 14:21:14 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-12 13:41:02 +00:00
|
|
|
* @var WooCommerce The single instance of the class
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* @var WC_Session session
|
|
|
|
*/
|
|
|
|
public $session = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WC_Query $query
|
|
|
|
*/
|
|
|
|
public $query = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WC_Product_Factory $product_factory
|
|
|
|
*/
|
|
|
|
public $product_factory = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WC_Countries $countries
|
|
|
|
*/
|
|
|
|
public $countries = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WC_Integrations $integrations
|
|
|
|
*/
|
|
|
|
public $integrations = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WC_Cart $cart
|
|
|
|
*/
|
|
|
|
public $cart = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WC_Customer $customer
|
|
|
|
*/
|
|
|
|
public $customer = null;
|
|
|
|
|
2014-07-03 11:38:55 +00:00
|
|
|
/**
|
2014-08-31 05:41:40 +00:00
|
|
|
* @var WC_Order_Factory $order_factory
|
|
|
|
*/
|
|
|
|
public $order_factory = null;
|
2014-07-03 11:38:55 +00:00
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
/**
|
|
|
|
* Main WooCommerce Instance
|
|
|
|
*
|
|
|
|
* Ensures only one instance of WooCommerce is loaded or can be loaded.
|
|
|
|
*
|
|
|
|
* @since 2.1
|
|
|
|
* @static
|
|
|
|
* @see WC()
|
2013-09-25 03:11:42 +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() {
|
2014-02-17 13:14:41 +00:00
|
|
|
_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() {
|
2014-02-17 13:14:41 +00:00
|
|
|
_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
|
|
|
/**
|
|
|
|
* Hook into actions and filters
|
|
|
|
* @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' ) );
|
2015-01-28 17:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-28 17:50:58 +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__ );
|
|
|
|
$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/' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-11-19 22:50:13 +00:00
|
|
|
/**
|
|
|
|
* Define constant if not already set
|
|
|
|
* @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?
|
|
|
|
* string $type ajax, frontend or admin
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() {
|
2015-01-28 18:01:30 +00:00
|
|
|
include_once( 'includes/class-wc-autoloader.php' );
|
2014-02-28 13:55:40 +00:00
|
|
|
include_once( 'includes/wc-core-functions.php' );
|
2014-11-20 20:56:24 +00:00
|
|
|
include_once( 'includes/wc-widget-functions.php' );
|
2014-12-16 20:54:48 +00:00
|
|
|
include_once( 'includes/wc-webhook-functions.php' );
|
2014-02-28 13:55:40 +00:00
|
|
|
include_once( 'includes/class-wc-install.php' );
|
2014-12-23 18:50:20 +00:00
|
|
|
include_once( 'includes/class-wc-geolocation.php' );
|
2014-02-28 13:55:40 +00:00
|
|
|
include_once( 'includes/class-wc-download-handler.php' );
|
|
|
|
include_once( 'includes/class-wc-comments.php' );
|
|
|
|
include_once( 'includes/class-wc-post-data.php' );
|
2015-03-20 12:28:26 +00:00
|
|
|
include_once( 'includes/class-wc-ajax.php' );
|
2013-06-11 14:59:54 +00:00
|
|
|
|
2014-11-25 23:21:39 +00:00
|
|
|
if ( $this->is_request( 'admin' ) ) {
|
2013-07-24 16:01:36 +00:00
|
|
|
include_once( 'includes/admin/class-wc-admin.php' );
|
2013-12-08 21:25:57 +00:00
|
|
|
}
|
2013-07-24 16:01:36 +00:00
|
|
|
|
2014-11-25 23:21:39 +00:00
|
|
|
if ( $this->is_request( 'frontend' ) ) {
|
2013-06-11 14:21:14 +00:00
|
|
|
$this->frontend_includes();
|
2013-12-08 21:25:57 +00:00
|
|
|
}
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2015-07-16 16:32:31 +00:00
|
|
|
if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-session.php' );
|
|
|
|
include_once( 'includes/class-wc-session-handler.php' );
|
|
|
|
}
|
|
|
|
|
2015-01-23 17:20:09 +00:00
|
|
|
if ( $this->is_request( 'cron' ) && 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) {
|
2015-01-23 16:36:52 +00:00
|
|
|
include_once( 'includes/class-wc-tracker.php' );
|
|
|
|
}
|
|
|
|
|
2014-08-31 05:41:40 +00:00
|
|
|
$this->query = include( 'includes/class-wc-query.php' ); // The main query class
|
2015-01-28 17:50:58 +00:00
|
|
|
$this->api = include( 'includes/class-wc-api.php' ); // API Class
|
2013-07-23 16:05:01 +00:00
|
|
|
|
2015-07-16 16:32:31 +00:00
|
|
|
include_once( 'includes/class-wc-auth.php' ); // Auth Class
|
2014-08-31 05:41:40 +00:00
|
|
|
include_once( 'includes/class-wc-post-types.php' ); // Registers post types
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-product.php' ); // Products
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-order.php' ); // Orders
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
|
|
|
|
include_once( 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service
|
|
|
|
include_once( 'includes/class-wc-product-factory.php' ); // Product factory
|
|
|
|
include_once( 'includes/class-wc-countries.php' ); // Defines countries and states
|
|
|
|
include_once( 'includes/class-wc-integrations.php' ); // Loads integrations
|
|
|
|
include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper
|
2014-11-25 23:21:39 +00:00
|
|
|
include_once( 'includes/class-wc-language-pack-upgrader.php' ); // Download/update languages
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include required frontend files.
|
|
|
|
*/
|
|
|
|
public function frontend_includes() {
|
2014-06-04 10:16:19 +00:00
|
|
|
include_once( 'includes/wc-cart-functions.php' );
|
|
|
|
include_once( 'includes/wc-notice-functions.php' );
|
|
|
|
include_once( 'includes/wc-template-hooks.php' );
|
2014-08-31 05:41:40 +00:00
|
|
|
include_once( 'includes/class-wc-template-loader.php' ); // Template Loader
|
|
|
|
include_once( 'includes/class-wc-frontend-scripts.php' ); // Frontend Scripts
|
|
|
|
include_once( 'includes/class-wc-form-handler.php' ); // Form Handlers
|
|
|
|
include_once( 'includes/class-wc-cart.php' ); // The main cart class
|
|
|
|
include_once( 'includes/class-wc-tax.php' ); // Tax class
|
|
|
|
include_once( 'includes/class-wc-customer.php' ); // Customer class
|
|
|
|
include_once( 'includes/class-wc-shortcodes.php' ); // Shortcodes class
|
|
|
|
include_once( 'includes/class-wc-https.php' ); // https Helper
|
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() {
|
2015-03-02 13:31:49 +00:00
|
|
|
include_once( 'includes/wc-template-functions.php' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init WooCommerce when WordPress Initialises.
|
|
|
|
*/
|
|
|
|
public function init() {
|
2013-09-12 13:41:02 +00:00
|
|
|
// Before init action
|
2013-06-11 14:21:14 +00:00
|
|
|
do_action( 'before_woocommerce_init' );
|
|
|
|
|
|
|
|
// Set up localisation
|
|
|
|
$this->load_plugin_textdomain();
|
|
|
|
|
|
|
|
// Load class instances
|
2014-08-31 05:41:40 +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
|
2013-06-11 14:21:14 +00:00
|
|
|
|
2015-07-16 16:32:31 +00:00
|
|
|
// Session class, handles session data for users - can be overwritten if custom handler is needed
|
|
|
|
if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {
|
|
|
|
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
|
|
|
|
$this->session = new $session_class();
|
|
|
|
}
|
|
|
|
|
2013-06-11 14:21:14 +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' ) ) {
|
2014-08-31 05:41:40 +00:00
|
|
|
$this->cart = new WC_Cart(); // Cart class, stores the cart contents
|
|
|
|
$this->customer = new WC_Customer(); // Customer class, handles data such as customer location
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 20:27:50 +00:00
|
|
|
$this->load_webhooks();
|
|
|
|
|
2013-06-11 14:21:14 +00:00
|
|
|
// Init action
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* Admin Locales are found in:
|
|
|
|
* - WP_LANG_DIR/woocommerce/woocommerce-admin-LOCALE.mo
|
|
|
|
* - WP_LANG_DIR/plugins/woocommerce-admin-LOCALE.mo
|
|
|
|
*
|
|
|
|
* Frontend/global Locales found in:
|
|
|
|
* - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo
|
|
|
|
* - woocommerce/i18n/languages/woocommerce-LOCALE.mo (which if not found falls back to:)
|
|
|
|
* - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo
|
2013-06-11 14:21:14 +00:00
|
|
|
*/
|
|
|
|
public function load_plugin_textdomain() {
|
|
|
|
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce' );
|
|
|
|
|
2014-11-25 23:21:39 +00:00
|
|
|
if ( $this->is_request( 'admin' ) ) {
|
2014-11-19 16:39:26 +00:00
|
|
|
load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-admin-' . $locale . '.mo' );
|
|
|
|
load_textdomain( 'woocommerce', WP_LANG_DIR . '/plugins/woocommerce-admin-' . $locale . '.mo' );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
2014-05-28 16:06:00 +00:00
|
|
|
|
2014-11-19 16:39:26 +00:00
|
|
|
load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-' . $locale . '.mo' );
|
2014-09-19 09:29:19 +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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure post thumbnail support is turned on
|
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Add WC Image sizes to WP
|
|
|
|
*
|
|
|
|
* @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' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the WC API URL for a given request
|
|
|
|
*
|
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
|
|
|
|
|
|
|
return esc_url_raw( $api_request_url );
|
2013-06-11 14:21:14 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 20:27:50 +00:00
|
|
|
/**
|
|
|
|
* Load & enqueue active webhooks
|
|
|
|
*
|
|
|
|
* @since 2.2
|
|
|
|
*/
|
2014-11-25 23:21:39 +00:00
|
|
|
private function load_webhooks() {
|
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',
|
|
|
|
'posts_per_page' => -1
|
|
|
|
) );
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Get gateways class
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* Get shipping class
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|