2013-06-06 13:20:47 +00:00
|
|
|
<?php
|
2015-02-04 16:07:33 +00:00
|
|
|
/**
|
2015-11-03 13:53:50 +00:00
|
|
|
* Handle frontend scripts
|
2015-02-04 16:07:33 +00:00
|
|
|
*
|
2018-03-22 19:01:03 +00:00
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @version 2.3.0
|
2015-02-04 16:07:33 +00:00
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2015-02-04 16:07:33 +00:00
|
|
|
exit;
|
2014-05-28 13:52:50 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 12:31:41 +00:00
|
|
|
/**
|
2018-03-22 19:01:03 +00:00
|
|
|
* Frontend scripts class.
|
2013-06-11 12:31:41 +00:00
|
|
|
*/
|
|
|
|
class WC_Frontend_Scripts {
|
2013-06-06 13:20:47 +00:00
|
|
|
|
2014-09-24 09:57:39 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Contains an array of script handles registered by WC.
|
2018-03-22 19:01:03 +00:00
|
|
|
*
|
2014-09-24 09:57:39 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $scripts = array();
|
|
|
|
|
2015-10-01 13:31:05 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Contains an array of script handles registered by WC.
|
2018-03-22 19:01:03 +00:00
|
|
|
*
|
2015-10-01 13:31:05 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $styles = array();
|
|
|
|
|
2014-09-24 09:57:39 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Contains an array of script handles localized by WC.
|
2018-03-22 19:01:03 +00:00
|
|
|
*
|
2014-09-24 09:57:39 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $wp_localize_scripts = array();
|
|
|
|
|
2013-06-11 12:31:41 +00:00
|
|
|
/**
|
2015-02-04 16:07:33 +00:00
|
|
|
* Hook in methods.
|
2013-06-11 12:31:41 +00:00
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function init() {
|
|
|
|
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
|
2014-05-30 11:01:01 +00:00
|
|
|
add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
|
|
|
|
add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
|
2013-06-11 12:31:41 +00:00
|
|
|
}
|
2013-06-06 13:20:47 +00:00
|
|
|
|
2013-08-02 11:27:31 +00:00
|
|
|
/**
|
2015-02-04 16:07:33 +00:00
|
|
|
* Get styles for the frontend.
|
2017-01-27 14:13:54 +00:00
|
|
|
*
|
2013-08-02 11:27:31 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function get_styles() {
|
2018-03-22 19:01:03 +00:00
|
|
|
return apply_filters(
|
|
|
|
'woocommerce_enqueue_styles', array(
|
|
|
|
'woocommerce-layout' => array(
|
|
|
|
'src' => self::get_asset_url( 'assets/css/woocommerce-layout.css' ),
|
|
|
|
'deps' => '',
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
'media' => 'all',
|
|
|
|
'has_rtl' => true,
|
|
|
|
),
|
|
|
|
'woocommerce-smallscreen' => array(
|
|
|
|
'src' => self::get_asset_url( 'assets/css/woocommerce-smallscreen.css' ),
|
|
|
|
'deps' => 'woocommerce-layout',
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', '768px' ) . ')',
|
|
|
|
'has_rtl' => true,
|
|
|
|
),
|
|
|
|
'woocommerce-general' => array(
|
|
|
|
'src' => self::get_asset_url( 'assets/css/woocommerce.css' ),
|
|
|
|
'deps' => '',
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
'media' => 'all',
|
|
|
|
'has_rtl' => true,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2013-08-02 11:27:31 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 18:34:30 +00:00
|
|
|
/**
|
2017-07-03 13:58:53 +00:00
|
|
|
* Return asset URL.
|
2017-05-12 08:48:46 +00:00
|
|
|
*
|
2018-03-22 19:01:03 +00:00
|
|
|
* @param string $path Assets path.
|
2017-05-12 08:48:46 +00:00
|
|
|
* @return string
|
2016-12-05 18:34:30 +00:00
|
|
|
*/
|
|
|
|
private static function get_asset_url( $path ) {
|
2017-07-03 13:58:53 +00:00
|
|
|
return apply_filters( 'woocommerce_get_asset_url', plugins_url( $path, WC_PLUGIN_FILE ), $path );
|
2016-12-05 18:34:30 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 09:57:39 +00:00
|
|
|
/**
|
2015-02-04 16:07:33 +00:00
|
|
|
* Register a script for use.
|
2014-09-24 09:57:39 +00:00
|
|
|
*
|
|
|
|
* @uses wp_register_script()
|
2018-03-22 19:01:03 +00:00
|
|
|
* @param string $handle Name of the script. Should be unique.
|
|
|
|
* @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
|
|
|
|
* @param string[] $deps An array of registered script handles this script depends on.
|
|
|
|
* @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
|
|
|
* @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
|
2014-09-24 09:57:39 +00:00
|
|
|
*/
|
|
|
|
private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
|
|
|
self::$scripts[] = $handle;
|
|
|
|
wp_register_script( $handle, $path, $deps, $version, $in_footer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-04 16:07:33 +00:00
|
|
|
* Register and enqueue a script for use.
|
2014-09-24 09:57:39 +00:00
|
|
|
*
|
|
|
|
* @uses wp_enqueue_script()
|
2018-03-22 19:01:03 +00:00
|
|
|
* @param string $handle Name of the script. Should be unique.
|
|
|
|
* @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
|
|
|
|
* @param string[] $deps An array of registered script handles this script depends on.
|
|
|
|
* @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
|
|
|
* @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
|
2014-09-24 09:57:39 +00:00
|
|
|
*/
|
|
|
|
private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = WC_VERSION, $in_footer = true ) {
|
2018-03-22 19:01:03 +00:00
|
|
|
if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
|
2014-09-24 09:57:39 +00:00
|
|
|
self::register_script( $handle, $path, $deps, $version, $in_footer );
|
|
|
|
}
|
|
|
|
wp_enqueue_script( $handle );
|
|
|
|
}
|
|
|
|
|
2015-10-01 13:31:05 +00:00
|
|
|
/**
|
|
|
|
* Register a style for use.
|
|
|
|
*
|
|
|
|
* @uses wp_register_style()
|
2018-03-22 19:01:03 +00:00
|
|
|
* @param string $handle Name of the stylesheet. Should be unique.
|
|
|
|
* @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
|
|
|
* @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
|
|
|
|
* @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
|
|
|
* @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
|
|
|
|
* @param boolean $has_rtl If has RTL version to load too.
|
2015-10-01 13:31:05 +00:00
|
|
|
*/
|
2017-01-20 18:29:48 +00:00
|
|
|
private static function register_style( $handle, $path, $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
|
2015-10-01 13:31:05 +00:00
|
|
|
self::$styles[] = $handle;
|
|
|
|
wp_register_style( $handle, $path, $deps, $version, $media );
|
2017-01-20 18:29:48 +00:00
|
|
|
|
|
|
|
if ( $has_rtl ) {
|
|
|
|
wp_style_add_data( $handle, 'rtl', 'replace' );
|
|
|
|
}
|
2015-10-01 13:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register and enqueue a styles for use.
|
|
|
|
*
|
|
|
|
* @uses wp_enqueue_style()
|
2018-03-22 19:01:03 +00:00
|
|
|
* @param string $handle Name of the stylesheet. Should be unique.
|
|
|
|
* @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
|
|
|
* @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
|
|
|
|
* @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
|
|
|
|
* @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
|
|
|
|
* @param boolean $has_rtl If has RTL version to load too.
|
2015-10-01 13:31:05 +00:00
|
|
|
*/
|
2017-01-20 18:29:48 +00:00
|
|
|
private static function enqueue_style( $handle, $path = '', $deps = array(), $version = WC_VERSION, $media = 'all', $has_rtl = false ) {
|
2018-03-22 19:01:03 +00:00
|
|
|
if ( ! in_array( $handle, self::$styles, true ) && $path ) {
|
2017-01-20 18:29:48 +00:00
|
|
|
self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
|
2015-10-01 13:31:05 +00:00
|
|
|
}
|
|
|
|
wp_enqueue_style( $handle );
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:34:30 +00:00
|
|
|
/**
|
|
|
|
* Register all WC scripts.
|
|
|
|
*/
|
|
|
|
private static function register_scripts() {
|
|
|
|
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
|
|
|
$register_scripts = array(
|
2018-03-22 19:01:03 +00:00
|
|
|
'flexslider' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
2018-02-02 11:56:02 +00:00
|
|
|
'version' => '2.7.0',
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'js-cookie' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),
|
|
|
|
'deps' => array(),
|
2017-04-18 10:44:51 +00:00
|
|
|
'version' => '2.1.4',
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'jquery-blockui' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => '2.70',
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'jquery-cookie' => array( // deprecated.
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/jquery-cookie/jquery.cookie' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => '1.4.1',
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'jquery-payment' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/jquery-payment/jquery.payment' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
2017-05-22 15:37:08 +00:00
|
|
|
'version' => '3.0.0',
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'photoswipe' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe' . $suffix . '.js' ),
|
|
|
|
'deps' => array(),
|
|
|
|
'version' => '4.1.1',
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'photoswipe-ui-default' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/photoswipe/photoswipe-ui-default' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'photoswipe' ),
|
|
|
|
'version' => '4.1.1',
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'prettyPhoto' => array( // deprecated.
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => '3.1.6',
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'prettyPhoto-init' => array( // deprecated.
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'prettyPhoto' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'select2' => array(
|
2017-07-06 15:43:10 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/select2/select2.full' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => '4.0.3',
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'selectWoo' => array(
|
2017-06-26 18:50:08 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
|
2016-12-05 18:34:30 +00:00
|
|
|
'deps' => array( 'jquery' ),
|
2018-03-15 18:52:07 +00:00
|
|
|
'version' => '1.0.4',
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-address-i18n' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/address-i18n' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-add-payment-method' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/add-payment-method' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'woocommerce' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-cart' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/cart' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'wc-country-select', 'wc-address-i18n' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-cart-fragments' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/cart-fragments' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'js-cookie' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-checkout' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/checkout' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-country-select' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/country-select' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-credit-card-form' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/credit-card-form' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'jquery-payment' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-add-to-cart' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-add-to-cart-variation' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/add-to-cart-variation' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'wp-util' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-geolocation' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/geolocation' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-lost-password' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/lost-password' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'woocommerce' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
|
|
|
'wc-password-strength-meter' => array(
|
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/password-strength-meter' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'password-strength-meter' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc-single-product' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/single-product' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'woocommerce' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/frontend/woocommerce' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery', 'jquery-blockui', 'js-cookie' ),
|
|
|
|
'version' => WC_VERSION,
|
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'zoom' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/js/zoom/jquery.zoom' . $suffix . '.js' ),
|
|
|
|
'deps' => array( 'jquery' ),
|
|
|
|
'version' => '1.7.15',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
foreach ( $register_scripts as $name => $props ) {
|
|
|
|
self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register all WC sty;es.
|
|
|
|
*/
|
|
|
|
private static function register_styles() {
|
|
|
|
$register_styles = array(
|
2018-03-22 19:01:03 +00:00
|
|
|
'photoswipe' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/css/photoswipe/photoswipe.css' ),
|
|
|
|
'deps' => array(),
|
|
|
|
'version' => WC_VERSION,
|
2017-01-20 18:29:48 +00:00
|
|
|
'has_rtl' => false,
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'photoswipe-default-skin' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/css/photoswipe/default-skin/default-skin.css' ),
|
|
|
|
'deps' => array( 'photoswipe' ),
|
|
|
|
'version' => WC_VERSION,
|
2017-01-20 18:29:48 +00:00
|
|
|
'has_rtl' => false,
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
2018-03-22 19:01:03 +00:00
|
|
|
'select2' => array(
|
2016-12-05 18:34:30 +00:00
|
|
|
'src' => self::get_asset_url( 'assets/css/select2.css' ),
|
|
|
|
'deps' => array(),
|
|
|
|
'version' => WC_VERSION,
|
2017-02-10 19:39:28 +00:00
|
|
|
'has_rtl' => false,
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
|
|
|
'woocommerce_prettyPhoto_css' => array( // deprecated.
|
|
|
|
'src' => self::get_asset_url( 'assets/css/prettyPhoto.css' ),
|
|
|
|
'deps' => array(),
|
|
|
|
'version' => WC_VERSION,
|
2017-01-20 18:29:48 +00:00
|
|
|
'has_rtl' => true,
|
2016-12-05 18:34:30 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
foreach ( $register_styles as $name => $props ) {
|
2017-01-20 18:29:48 +00:00
|
|
|
self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
|
2016-12-05 18:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 13:20:47 +00:00
|
|
|
/**
|
|
|
|
* Register/queue frontend scripts.
|
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function load_scripts() {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $post;
|
2013-06-06 13:20:47 +00:00
|
|
|
|
2015-10-05 18:12:19 +00:00
|
|
|
if ( ! did_action( 'before_woocommerce_init' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:34:30 +00:00
|
|
|
self::register_scripts();
|
|
|
|
self::register_styles();
|
2013-06-06 13:20:47 +00:00
|
|
|
|
2016-12-05 18:34:30 +00:00
|
|
|
if ( 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
|
|
|
|
self::enqueue_script( 'wc-add-to-cart' );
|
2014-09-24 09:57:39 +00:00
|
|
|
}
|
|
|
|
if ( is_cart() ) {
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_script( 'wc-cart' );
|
2014-09-24 09:57:39 +00:00
|
|
|
}
|
2017-07-10 12:14:27 +00:00
|
|
|
if ( is_cart() || is_checkout() || is_account_page() ) {
|
2017-07-06 15:43:10 +00:00
|
|
|
self::enqueue_script( 'selectWoo' );
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_style( 'select2' );
|
2015-10-09 14:22:31 +00:00
|
|
|
|
2016-12-05 18:34:30 +00:00
|
|
|
// Password strength meter. Load in checkout, account login and edit account page.
|
2016-11-11 17:21:06 +00:00
|
|
|
if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() || is_lost_password_page() ) {
|
2015-10-09 16:31:47 +00:00
|
|
|
self::enqueue_script( 'wc-password-strength-meter' );
|
2015-10-09 14:22:31 +00:00
|
|
|
}
|
2014-09-24 09:57:39 +00:00
|
|
|
}
|
2013-06-06 13:20:47 +00:00
|
|
|
if ( is_checkout() ) {
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_script( 'wc-checkout' );
|
2013-06-06 13:20:47 +00:00
|
|
|
}
|
2014-09-24 09:57:39 +00:00
|
|
|
if ( is_add_payment_method_page() ) {
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_script( 'wc-add-payment-method' );
|
2014-02-08 08:58:50 +00:00
|
|
|
}
|
2014-10-16 19:59:45 +00:00
|
|
|
if ( is_lost_password_page() ) {
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_script( 'wc-lost-password' );
|
2014-10-16 19:59:45 +00:00
|
|
|
}
|
2017-01-27 14:13:54 +00:00
|
|
|
|
|
|
|
// Load gallery scripts on product pages only if supported.
|
2016-10-13 14:25:42 +00:00
|
|
|
if ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) {
|
2017-02-09 12:34:06 +00:00
|
|
|
if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
|
2017-01-27 14:13:54 +00:00
|
|
|
self::enqueue_script( 'zoom' );
|
|
|
|
}
|
2017-02-09 12:34:06 +00:00
|
|
|
if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
|
2017-01-27 14:13:54 +00:00
|
|
|
self::enqueue_script( 'flexslider' );
|
|
|
|
}
|
2017-02-09 12:34:06 +00:00
|
|
|
if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
|
2017-01-27 14:13:54 +00:00
|
|
|
self::enqueue_script( 'photoswipe-ui-default' );
|
|
|
|
self::enqueue_style( 'photoswipe-default-skin' );
|
2017-03-15 13:36:11 +00:00
|
|
|
add_action( 'wp_footer', 'woocommerce_photoswipe' );
|
2017-01-27 14:13:54 +00:00
|
|
|
}
|
2014-09-24 09:57:39 +00:00
|
|
|
self::enqueue_script( 'wc-single-product' );
|
|
|
|
}
|
2017-01-27 14:13:54 +00:00
|
|
|
|
2015-06-17 13:16:35 +00:00
|
|
|
if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
|
2016-12-05 18:34:30 +00:00
|
|
|
$ua = wc_get_user_agent(); // Exclude common bots from geolocation by user agent.
|
2016-04-01 10:14:24 +00:00
|
|
|
|
|
|
|
if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_script( 'wc-geolocation' );
|
2016-04-01 10:14:24 +00:00
|
|
|
}
|
2015-06-17 13:16:35 +00:00
|
|
|
}
|
2013-06-06 13:20:47 +00:00
|
|
|
|
2018-03-22 19:01:03 +00:00
|
|
|
// Global frontend scripts.
|
2016-12-05 18:34:30 +00:00
|
|
|
self::enqueue_script( 'woocommerce' );
|
|
|
|
self::enqueue_script( 'wc-cart-fragments' );
|
2013-06-06 13:20:47 +00:00
|
|
|
|
2018-03-22 19:01:03 +00:00
|
|
|
// CSS Styles.
|
|
|
|
$enqueue_styles = self::get_styles();
|
|
|
|
if ( $enqueue_styles ) {
|
2014-05-28 13:52:50 +00:00
|
|
|
foreach ( $enqueue_styles as $handle => $args ) {
|
2017-01-20 18:29:48 +00:00
|
|
|
if ( ! isset( $args['has_rtl'] ) ) {
|
|
|
|
$args['has_rtl'] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
|
2014-05-28 13:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-06 13:20:47 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 11:01:01 +00:00
|
|
|
/**
|
2014-09-24 09:57:39 +00:00
|
|
|
* Localize a WC script once.
|
2018-03-22 19:01:03 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0 this needs less wp_script_is() calls due to https://core.trac.wordpress.org/ticket/28404 being added in WP 4.0.
|
|
|
|
* @param string $handle Script handle the data will be attached to.
|
2014-05-30 11:01:01 +00:00
|
|
|
*/
|
2014-09-24 09:57:39 +00:00
|
|
|
private static function localize_script( $handle ) {
|
2018-03-22 19:01:03 +00:00
|
|
|
if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
|
|
|
|
$data = self::get_script_data( $handle );
|
|
|
|
|
|
|
|
if ( ! $data ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:57:39 +00:00
|
|
|
$name = str_replace( '-', '_', $handle ) . '_params';
|
|
|
|
self::$wp_localize_scripts[] = $handle;
|
|
|
|
wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
|
2014-05-30 11:01:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 13:20:47 +00:00
|
|
|
/**
|
2015-02-04 16:07:33 +00:00
|
|
|
* Return data for script handles.
|
2018-03-22 19:01:03 +00:00
|
|
|
*
|
|
|
|
* @param string $handle Script handle the data will be attached to.
|
2014-09-24 09:57:39 +00:00
|
|
|
* @return array|bool
|
2013-06-06 13:20:47 +00:00
|
|
|
*/
|
2014-09-24 09:57:39 +00:00
|
|
|
private static function get_script_data( $handle ) {
|
|
|
|
global $wp;
|
|
|
|
|
|
|
|
switch ( $handle ) {
|
2018-03-22 19:01:03 +00:00
|
|
|
case 'woocommerce':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2015-06-17 13:16:35 +00:00
|
|
|
'ajax_url' => WC()->ajax_url(),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
2015-06-17 13:16:35 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-geolocation':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
2015-11-04 03:51:54 +00:00
|
|
|
'home_url' => home_url(),
|
|
|
|
'is_available' => ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() ) ? '1' : '0',
|
2018-03-22 19:01:03 +00:00
|
|
|
'hash' => isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : '', // WPCS: input var ok, CSRF ok.
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-single-product':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2014-09-24 09:57:39 +00:00
|
|
|
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
|
|
|
|
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
|
2018-03-22 19:01:03 +00:00
|
|
|
'flexslider' => apply_filters(
|
|
|
|
'woocommerce_single_product_carousel_options', array(
|
|
|
|
'rtl' => is_rtl(),
|
|
|
|
'animation' => 'slide',
|
|
|
|
'smoothHeight' => true,
|
|
|
|
'directionNav' => false,
|
|
|
|
'controlNav' => 'thumbnails',
|
|
|
|
'slideshow' => false,
|
|
|
|
'animationSpeed' => 500,
|
|
|
|
'animationLoop' => false, // Breaks photoswipe pagination if true.
|
|
|
|
'allowOneSlide' => false,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'zoom_enabled' => apply_filters( 'woocommerce_single_product_zoom_enabled', get_theme_support( 'wc-product-gallery-zoom' ) ),
|
|
|
|
'zoom_options' => apply_filters( 'woocommerce_single_product_zoom_options', array() ),
|
|
|
|
'photoswipe_enabled' => apply_filters( 'woocommerce_single_product_photoswipe_enabled', get_theme_support( 'wc-product-gallery-lightbox' ) ),
|
|
|
|
'photoswipe_options' => apply_filters(
|
|
|
|
'woocommerce_single_product_photoswipe_options', array(
|
|
|
|
'shareEl' => false,
|
|
|
|
'closeOnScroll' => false,
|
|
|
|
'history' => false,
|
|
|
|
'hideAnimationDuration' => 0,
|
|
|
|
'showAnimationDuration' => 0,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'flexslider_enabled' => apply_filters( 'woocommerce_single_product_flexslider_enabled', get_theme_support( 'wc-product-gallery-slider' ) ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-checkout':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2014-09-24 09:57:39 +00:00
|
|
|
'ajax_url' => WC()->ajax_url(),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
2014-12-08 06:15:03 +00:00
|
|
|
'update_order_review_nonce' => wp_create_nonce( 'update-order-review' ),
|
|
|
|
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
|
|
|
|
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
|
2018-03-22 19:01:03 +00:00
|
|
|
'checkout_url' => WC_AJAX::get_endpoint( 'checkout' ),
|
2015-01-26 14:24:00 +00:00
|
|
|
'is_checkout' => is_page( wc_get_page_id( 'checkout' ) ) && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0,
|
2016-09-02 01:51:31 +00:00
|
|
|
'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
2015-05-15 12:51:51 +00:00
|
|
|
'i18n_checkout_error' => esc_attr__( 'Error processing checkout. Please try again.', 'woocommerce' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-address-i18n':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2018-03-22 19:01:03 +00:00
|
|
|
'locale' => wp_json_encode( WC()->countries->get_country_locale() ),
|
|
|
|
'locale_fields' => wp_json_encode( WC()->countries->get_country_locale_field_selectors() ),
|
2014-09-24 09:57:39 +00:00
|
|
|
'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),
|
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-cart':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2014-09-24 09:57:39 +00:00
|
|
|
'ajax_url' => WC()->ajax_url(),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
|
|
|
'update_shipping_method_nonce' => wp_create_nonce( 'update-shipping-method' ),
|
|
|
|
'apply_coupon_nonce' => wp_create_nonce( 'apply-coupon' ),
|
|
|
|
'remove_coupon_nonce' => wp_create_nonce( 'remove-coupon' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-cart-fragments':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2014-09-24 09:57:39 +00:00
|
|
|
'ajax_url' => WC()->ajax_url(),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
2018-01-15 16:03:27 +00:00
|
|
|
'cart_hash_key' => apply_filters( 'woocommerce_cart_hash_key', 'wc_cart_hash_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
|
2017-06-08 12:47:34 +00:00
|
|
|
'fragment_name' => apply_filters( 'woocommerce_cart_fragment_name', 'wc_fragments_' . md5( get_current_blog_id() . '_' . get_site_url( get_current_blog_id(), '/' ) ) ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-add-to-cart':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2014-09-24 09:57:39 +00:00
|
|
|
'ajax_url' => WC()->ajax_url(),
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
2016-10-12 10:16:30 +00:00
|
|
|
'i18n_view_cart' => esc_attr__( 'View cart', 'woocommerce' ),
|
2015-10-28 17:56:31 +00:00
|
|
|
'cart_url' => apply_filters( 'woocommerce_add_to_cart_redirect', wc_get_cart_url() ),
|
2014-09-24 09:57:39 +00:00
|
|
|
'is_cart' => is_cart(),
|
2016-08-27 01:46:45 +00:00
|
|
|
'cart_redirect_after_add' => get_option( 'woocommerce_cart_redirect_after_add' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-add-to-cart-variation':
|
|
|
|
// We also need the wp.template for this script :).
|
2015-12-04 14:28:32 +00:00
|
|
|
wc_get_template( 'single-product/add-to-cart/variation.php' );
|
|
|
|
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2018-03-22 19:01:03 +00:00
|
|
|
'wc_ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'woocommerce' ),
|
2016-02-08 16:21:02 +00:00
|
|
|
'i18n_make_a_selection_text' => esc_attr__( 'Please select some product options before adding this product to your cart.', 'woocommerce' ),
|
2016-08-27 01:46:45 +00:00
|
|
|
'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-country-select':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2018-03-22 19:01:03 +00:00
|
|
|
'countries' => wp_json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
|
2016-01-27 10:53:59 +00:00
|
|
|
'i18n_select_state_text' => esc_attr__( 'Select an option…', 'woocommerce' ),
|
2015-03-03 10:58:06 +00:00
|
|
|
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'woocommerce' ),
|
|
|
|
'i18n_searching' => _x( 'Searching…', 'enhanced select', 'woocommerce' ),
|
2014-09-24 09:57:39 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
|
|
|
case 'wc-password-strength-meter':
|
2017-12-06 10:03:16 +00:00
|
|
|
$params = array(
|
2016-01-28 15:36:24 +00:00
|
|
|
'min_password_strength' => apply_filters( 'woocommerce_min_password_strength', 3 ),
|
|
|
|
'i18n_password_error' => esc_attr__( 'Please enter a stronger password.', 'woocommerce' ),
|
2017-03-10 03:47:17 +00:00
|
|
|
'i18n_password_hint' => esc_attr( wp_get_password_hint() ),
|
2016-01-28 15:36:24 +00:00
|
|
|
);
|
2018-03-22 19:01:03 +00:00
|
|
|
break;
|
2017-12-06 10:03:16 +00:00
|
|
|
default:
|
|
|
|
$params = false;
|
2013-06-06 13:20:47 +00:00
|
|
|
}
|
2017-12-06 10:03:16 +00:00
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_get_script_data', $params, $handle );
|
2013-06-06 13:20:47 +00:00
|
|
|
}
|
2013-08-02 11:06:32 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-24 09:57:39 +00:00
|
|
|
* Localize scripts only when enqueued.
|
2013-08-02 11:06:32 +00:00
|
|
|
*/
|
2014-09-24 09:57:39 +00:00
|
|
|
public static function localize_printed_scripts() {
|
|
|
|
foreach ( self::$scripts as $handle ) {
|
|
|
|
self::localize_script( $handle );
|
2013-08-02 11:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-11 12:31:41 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:52:50 +00:00
|
|
|
WC_Frontend_Scripts::init();
|