Enabled product bundles
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Admin
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_module_settings_admin_url' ) ) {
|
||||
/**
|
||||
* wcj_get_module_settings_admin_url.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 3.3.0
|
||||
* @todo use this function where needed
|
||||
*/
|
||||
function wcj_get_module_settings_admin_url( $module_id ) {
|
||||
return admin_url( 'admin.php?page=wc-settings&tab=jetpack&wcj-cat=' . wcj_get_module_category( $module_id ) . '§ion=' . $module_id );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_module_category' ) ) {
|
||||
/**
|
||||
* wcj_get_module_category.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 3.3.0
|
||||
* @todo better solution for `global $wcj_modules_cats`
|
||||
* @todo use this function where needed (e.g. in `class-wc-settings-jetpack.php`)
|
||||
*/
|
||||
function wcj_get_module_category( $module_id ) {
|
||||
global $wcj_modules_cats;
|
||||
if ( ! isset( $wcj_modules_cats ) ) {
|
||||
$wcj_modules_cats = include( WCJ_PLUGIN_PATH . '/includes/admin/wcj-modules-cats.php' );
|
||||
}
|
||||
foreach ( $wcj_modules_cats as $cat_id => $cat_data ) {
|
||||
if ( ! empty( $cat_data['all_cat_ids'] ) && in_array( $module_id, $cat_data['all_cat_ids'] ) ) {
|
||||
return $cat_id;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_ids_for_meta_box_options' ) ) {
|
||||
/**
|
||||
* wcj_get_product_ids_for_meta_box_options.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.3.0
|
||||
* @todo use this function where needed
|
||||
*/
|
||||
function wcj_get_product_ids_for_meta_box_options( $main_product_id, $do_get_all_variations = false ) {
|
||||
$_product = wc_get_product( $main_product_id );
|
||||
if ( ! $_product ) {
|
||||
return array();
|
||||
}
|
||||
$products = array();
|
||||
if ( $_product->is_type( 'variable' ) ) {
|
||||
if ( $do_get_all_variations ) {
|
||||
$all_variations = $_product->get_children();
|
||||
foreach ( $all_variations as $variation_id ) {
|
||||
$variation_product = wc_get_product( $variation_id );
|
||||
$products[ $variation_id ] = ' (' . wcj_get_product_formatted_variation( $variation_product, true ) . ')';
|
||||
}
|
||||
} else {
|
||||
$available_variations = $_product->get_available_variations();
|
||||
foreach ( $available_variations as $variation ) {
|
||||
$variation_product = wc_get_product( $variation['variation_id'] );
|
||||
$products[ $variation['variation_id'] ] = ' (' . wcj_get_product_formatted_variation( $variation_product, true ) . ')';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$products[ $main_product_id ] = '';
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_admin_product_edit_page' ) ) {
|
||||
/**
|
||||
* wcj_is_admin_product_edit_page.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.2.4
|
||||
* @todo use where appropriate
|
||||
* @todo (maybe) move to `wcj-functions-conditional.php`
|
||||
*/
|
||||
function wcj_is_admin_product_edit_page() {
|
||||
global $pagenow;
|
||||
if ( is_admin() && 'post.php' === $pagenow && isset( $_GET['action'] ) && 'edit' === $_GET['action'] && 'product' === get_post_type() ) {
|
||||
return true;
|
||||
} elseif ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'woocommerce_load_variations' === $_REQUEST['action'] ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_admin_notices_version_updated' ) ) {
|
||||
/**
|
||||
* wcj_admin_notices_version_updated.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_admin_notices_version_updated() {
|
||||
if ( get_option( WCJ_VERSION_OPTION ) === WCJ()->version ) {
|
||||
$class = 'notice notice-success is-dismissible';
|
||||
$message = sprintf( __( '<strong>Booster for WooCommerce</strong> plugin was successfully updated to version <strong>%s</strong>.', 'woocommerce-jetpack' ), WCJ()->version );
|
||||
echo sprintf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_settings_as_multiselect_or_text' ) ) {
|
||||
/**
|
||||
* wcj_get_settings_as_multiselect_or_text.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_get_settings_as_multiselect_or_text( $values, $multiselect_options, $is_multiselect ) {
|
||||
$prev_desc = ( isset( $values['desc'] ) ? $values['desc'] . ' ' : '' );
|
||||
return ( $is_multiselect ?
|
||||
array_merge( $values, array(
|
||||
'type' => 'multiselect',
|
||||
'class' => 'chosen_select',
|
||||
'options' => $multiselect_options,
|
||||
) ) :
|
||||
array_merge( $values, array(
|
||||
'type' => 'text',
|
||||
'desc' => $prev_desc . __( 'Enter comma separated list of IDs.', 'woocommerce-jetpack' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_convert_string_to_array' ) ) {
|
||||
/**
|
||||
* wcj_convert_string_to_array.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
* @todo check `custom_explode` function
|
||||
*/
|
||||
function wcj_convert_string_to_array( $value ) {
|
||||
if ( '' === $value ) {
|
||||
$value = array();
|
||||
} else {
|
||||
$value = str_replace( ' ', '', $value );
|
||||
$value = explode( ',', $value );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_convert_and_update_option_value' ) ) {
|
||||
/**
|
||||
* wcj_maybe_convert_and_update_option_value.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_maybe_convert_and_update_option_value( $options, $is_multiselect ) {
|
||||
foreach ( $options as $option ) {
|
||||
$value = get_option( $option['id'], $option['default'] );
|
||||
if ( ! $is_multiselect ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$value = implode( ',', $value );
|
||||
update_option( $option['id'], $value );
|
||||
}
|
||||
} else {
|
||||
if ( is_string( $value ) ) {
|
||||
$value = wcj_convert_string_to_array( $value );
|
||||
update_option( $option['id'], $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_convert_string_to_array' ) ) {
|
||||
/**
|
||||
* wcj_maybe_convert_string_to_array.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_maybe_convert_string_to_array( $value ) {
|
||||
if ( is_string( $value ) ) {
|
||||
$value = wcj_convert_string_to_array( $value );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_message_replaced_values' ) ) {
|
||||
/**
|
||||
* wcj_message_replaced_values.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo use this function in all applicable settings descriptions
|
||||
*/
|
||||
function wcj_message_replaced_values( $values ) {
|
||||
$message_template = ( 1 == count( $values ) ? __( 'Replaced value: %s', 'woocommerce-jetpack' ) : __( 'Replaced values: %s', 'woocommerce-jetpack' ) );
|
||||
return sprintf( $message_template, '<code>' . implode( '</code>, <code>', $values ) . '</code>' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_5_rocket_image' ) ) {
|
||||
/**
|
||||
* wcj_get_5_rocket_image.
|
||||
*
|
||||
* @version 2.5.5
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_get_5_rocket_image() {
|
||||
return '<img class="wcj-rocket-icon" src="' . wcj_plugin_url() . '/assets/images/5-rockets.png' . '" title="">';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_plus_message' ) ) {
|
||||
/**
|
||||
* wcj_get_plus_message.
|
||||
*
|
||||
* @version 3.6.0
|
||||
*/
|
||||
function wcj_get_plus_message( $value, $message_type, $args = array() ) {
|
||||
|
||||
switch ( $message_type ) {
|
||||
|
||||
case 'global':
|
||||
return '<div class="notice notice-warning">' .
|
||||
'<p><strong>' . __( 'Install Booster Plus to unlock all features', 'woocommerce-jetpack' ) . '</strong></p>' .
|
||||
'<p><span>' . sprintf( __( 'Some settings fields are locked and you will need %s to modify all locked fields.', 'woocommerce-jetpack'),
|
||||
'<a href="https://booster.io/plus/" target="_blank">Booster for WooCommerce Plus</a>' ) . '</span></p>' .
|
||||
'<p>' .
|
||||
'<a href="https://booster.io/plus/" target="_blank" class="button button-primary">' . __( 'Buy now', 'woocommerce-jetpack' ) . '</a>' . ' ' .
|
||||
'<a href="https://booster.io" target="_blank" class="button">' . __( 'Visit Booster Site', 'woocommerce-jetpack' ) . '</a>' .
|
||||
'</p>' .
|
||||
'</div>';
|
||||
|
||||
case 'desc':
|
||||
return sprintf( __( 'Get <a href="%s" target="_blank">Booster Plus</a> to change value.', 'woocommerce-jetpack' ), 'https://booster.io/plus/' );
|
||||
|
||||
case 'desc_advanced':
|
||||
return sprintf( __( 'Get <a href="%s" target="_blank">Booster Plus</a> to enable "%s" option.', 'woocommerce-jetpack' ), 'https://booster.io/plus/', $args['option'] );
|
||||
|
||||
case 'desc_advanced_no_link':
|
||||
return sprintf( __( 'Get Booster Plus to enable "%s" option.', 'woocommerce-jetpack' ), $args['option'] );
|
||||
|
||||
case 'desc_below':
|
||||
return sprintf( __( 'Get <a href="%s" target="_blank">Booster Plus</a> to change values below.', 'woocommerce-jetpack' ), 'https://booster.io/plus/' );
|
||||
|
||||
case 'desc_above':
|
||||
return sprintf( __( 'Get <a href="%s" target="_blank">Booster Plus</a> to change values above.', 'woocommerce-jetpack' ), 'https://booster.io/plus/' );
|
||||
|
||||
case 'desc_no_link':
|
||||
return __( 'Get Booster Plus to change value.', 'woocommerce-jetpack' );
|
||||
|
||||
case 'readonly':
|
||||
return array( 'readonly' => 'readonly' );
|
||||
|
||||
case 'disabled':
|
||||
return array( 'disabled' => 'disabled' );
|
||||
|
||||
case 'readonly_string':
|
||||
return 'readonly';
|
||||
|
||||
case 'disabled_string':
|
||||
return 'disabled';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Booster Core
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_plugin_url' ) ) {
|
||||
/**
|
||||
* wcj_plugin_url.
|
||||
*
|
||||
* @version 2.3.0
|
||||
* @todo (maybe) add `WCJ_PLUGIN_URL` constant instead
|
||||
*/
|
||||
function wcj_plugin_url() {
|
||||
return untrailingslashit( plugin_dir_url( realpath( dirname( __FILE__ ) . '/..' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_plugin_path' ) ) {
|
||||
/**
|
||||
* Get the plugin path.
|
||||
*
|
||||
* @return string
|
||||
* @todo use `WCJ_PLUGIN_PATH` constant instead
|
||||
*/
|
||||
function wcj_plugin_path() {
|
||||
return untrailingslashit( realpath( plugin_dir_path( __FILE__ ) . '/../..' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_module_enabled' ) ) {
|
||||
/*
|
||||
* wcj_is_module_enabled.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.4.0
|
||||
* @return boolean
|
||||
*/
|
||||
function wcj_is_module_enabled( $module_id ) {
|
||||
if ( 'modules_by_user_roles' != $module_id && wcj_is_module_enabled( 'modules_by_user_roles' ) ) {
|
||||
global $wcj_modules_by_user_roles_data;
|
||||
if ( ! isset( $wcj_modules_by_user_roles_data ) ) {
|
||||
if( ! function_exists( 'wp_get_current_user' ) ) {
|
||||
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
$wcj_modules_by_user_roles_data['role'] = ( isset( $current_user->roles ) && is_array( $current_user->roles ) && ! empty( $current_user->roles ) ?
|
||||
reset( $current_user->roles ) : 'guest' );
|
||||
$wcj_modules_by_user_roles_data['role'] = ( '' != $wcj_modules_by_user_roles_data['role'] ? $wcj_modules_by_user_roles_data['role'] : 'guest' );
|
||||
$wcj_modules_by_user_roles_data['modules_incl'] = get_option( 'wcj_modules_by_user_roles_incl_' . $wcj_modules_by_user_roles_data['role'], '' );
|
||||
$wcj_modules_by_user_roles_data['modules_excl'] = get_option( 'wcj_modules_by_user_roles_excl_' . $wcj_modules_by_user_roles_data['role'], '' );
|
||||
}
|
||||
if ( ! empty( $wcj_modules_by_user_roles_data['modules_incl'] ) && ! in_array( $module_id, $wcj_modules_by_user_roles_data['modules_incl'] ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! empty( $wcj_modules_by_user_roles_data['modules_excl'] ) && in_array( $module_id, $wcj_modules_by_user_roles_data['modules_excl'] ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return ( 'yes' === get_option( 'wcj_' . $module_id . '_enabled', 'no' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Core
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.3.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_is_plugin_active_simple' ) ) {
|
||||
/**
|
||||
* wcj_is_plugin_active_simple.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.8.0
|
||||
* @return bool
|
||||
*/
|
||||
function wcj_is_plugin_active_simple( $plugin ) {
|
||||
return (
|
||||
in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) ) ) ||
|
||||
( is_multisite() && array_key_exists( $plugin, get_site_option( 'active_sitewide_plugins', array() ) ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_active_plugins' ) ) {
|
||||
/**
|
||||
* wcj_get_active_plugins.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @return array
|
||||
*/
|
||||
function wcj_get_active_plugins() {
|
||||
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins', array() ) );
|
||||
if ( is_multisite() ) {
|
||||
$active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) );
|
||||
}
|
||||
return $active_plugins;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_plugin_active_by_file' ) ) {
|
||||
/**
|
||||
* wcj_is_plugin_active_by_file.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @return bool
|
||||
*/
|
||||
function wcj_is_plugin_active_by_file( $plugin_file ) {
|
||||
foreach ( wcj_get_active_plugins() as $active_plugin ) {
|
||||
$active_plugin = explode( '/', $active_plugin );
|
||||
if ( isset( $active_plugin[1] ) && $plugin_file === $active_plugin[1] ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_plugin_activated' ) ) {
|
||||
/**
|
||||
* wcj_is_plugin_activated.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @return bool
|
||||
*/
|
||||
function wcj_is_plugin_activated( $plugin_folder, $plugin_file ) {
|
||||
if ( wcj_is_plugin_active_simple( $plugin_folder . '/' . $plugin_file ) ) {
|
||||
return true;
|
||||
} else {
|
||||
return wcj_is_plugin_active_by_file( $plugin_file );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,600 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Country
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_add_european_union_countries' ) ) {
|
||||
/**
|
||||
* wcj_maybe_add_european_union_countries.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @todo use where needed
|
||||
*/
|
||||
function wcj_maybe_add_european_union_countries( $countries ) {
|
||||
if ( ! empty( $countries ) && in_array( 'EU', $countries ) ) {
|
||||
$countries = array_merge( $countries, wcj_get_european_union_countries() );
|
||||
}
|
||||
return $countries;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_country_by_ip' ) ) {
|
||||
/**
|
||||
* wcj_get_country_by_ip.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_get_country_by_ip() {
|
||||
// Get the country by IP
|
||||
$location = ( class_exists( 'WC_Geolocation' ) ? WC_Geolocation::geolocate_ip() : array( 'country' => '' ) );
|
||||
// Base fallback
|
||||
if ( empty( $location['country'] ) ) {
|
||||
$location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) );
|
||||
}
|
||||
return ( isset( $location['country'] ) ) ? $location['country'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_country_flag_by_code' ) ) {
|
||||
/**
|
||||
* wcj_get_country_flag_by_code.
|
||||
*
|
||||
@version 2.9.1
|
||||
*/
|
||||
function wcj_get_country_flag_by_code( $country_code ) {
|
||||
$img = '/assets/images/flag-icons/' . strtolower( $country_code ) . '.png';
|
||||
$img_path = wcj_plugin_path() . $img;
|
||||
$img_src = wcj_plugin_url() . ( file_exists( $img_path ) ? $img : '/assets/images/flag-icons/no-flag.png' );
|
||||
return '<img src="' . $img_src . '" title="' . wcj_get_country_name_by_code( $country_code ) . '">';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_customer_country' ) ) {
|
||||
/**
|
||||
* wcj_get_customer_country.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @return string
|
||||
* @todo re-check: there is also `wcj_customer_get_country()`
|
||||
*/
|
||||
function wcj_get_customer_country( $user_id ) {
|
||||
$user_meta = get_user_meta( $user_id );
|
||||
$billing_country = isset( $user_meta['billing_country'][0] ) ? $user_meta['billing_country'][0] : '';
|
||||
$shipping_country = isset( $user_meta['shipping_country'][0] ) ? $user_meta['shipping_country'][0] : '';
|
||||
return ( '' == $billing_country ) ? $shipping_country : $billing_country;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_european_union_countries_with_vat' ) ) {
|
||||
/**
|
||||
* wcj_get_european_union_countries_with_vat.
|
||||
*
|
||||
* @version 3.2.0
|
||||
* @return array
|
||||
* @todo check `MC`, `IM`
|
||||
*/
|
||||
function wcj_get_european_union_countries_with_vat() {
|
||||
return array(
|
||||
'AT' => 20,
|
||||
'BE' => 21,
|
||||
'BG' => 20,
|
||||
'CY' => 19,
|
||||
'CZ' => 21,
|
||||
'DE' => 19,
|
||||
'DK' => 25,
|
||||
'EE' => 20,
|
||||
'ES' => 21,
|
||||
'FI' => 24,
|
||||
'FR' => 20,
|
||||
'GB' => 20,
|
||||
'GR' => 24, // 23
|
||||
'HU' => 27,
|
||||
'HR' => 25,
|
||||
'IE' => 23,
|
||||
'IT' => 22,
|
||||
'LT' => 21,
|
||||
'LU' => 17,
|
||||
'LV' => 21,
|
||||
'MT' => 18,
|
||||
'NL' => 21,
|
||||
'PL' => 23,
|
||||
'PT' => 23,
|
||||
'RO' => 19, // 20 // 24
|
||||
'SE' => 25,
|
||||
'SI' => 22,
|
||||
'SK' => 20,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_european_union_countries' ) ) {
|
||||
/**
|
||||
* wcj_get_european_union_countries.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_get_european_union_countries() {
|
||||
return array_keys( wcj_get_european_union_countries_with_vat() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_country_name_by_code' ) ) {
|
||||
/**
|
||||
* Get country name by country code.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @return string on success, boolean false otherwise
|
||||
*/
|
||||
function wcj_get_country_name_by_code( $country_code ) {
|
||||
$countries = wcj_get_countries();
|
||||
return ( isset( $countries[ $country_code ] ) ) ? $countries[ $country_code ] : false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_states' ) ) {
|
||||
/**
|
||||
* Get all states array.
|
||||
*
|
||||
* @version 2.4.4
|
||||
* @since 2.4.4
|
||||
* @return array
|
||||
*/
|
||||
function wcj_get_states() {
|
||||
$base_country = WC()->countries->get_base_country();
|
||||
$states = WC()->countries->get_states( $base_country );
|
||||
return ( isset( $states ) && ! empty( $states ) ) ? $states : array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_countries' ) ) {
|
||||
/**
|
||||
* Get all countries array.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @return array
|
||||
*/
|
||||
function wcj_get_countries() {
|
||||
return array(
|
||||
'AF' => __( 'Afghanistan', 'woocommerce' ),
|
||||
'AX' => __( 'Åland Islands', 'woocommerce' ),
|
||||
'AL' => __( 'Albania', 'woocommerce' ),
|
||||
'DZ' => __( 'Algeria', 'woocommerce' ),
|
||||
'AD' => __( 'Andorra', 'woocommerce' ),
|
||||
'AO' => __( 'Angola', 'woocommerce' ),
|
||||
'AI' => __( 'Anguilla', 'woocommerce' ),
|
||||
'AQ' => __( 'Antarctica', 'woocommerce' ),
|
||||
'AG' => __( 'Antigua and Barbuda', 'woocommerce' ),
|
||||
'AR' => __( 'Argentina', 'woocommerce' ),
|
||||
'AM' => __( 'Armenia', 'woocommerce' ),
|
||||
'AW' => __( 'Aruba', 'woocommerce' ),
|
||||
'AU' => __( 'Australia', 'woocommerce' ),
|
||||
'AT' => __( 'Austria', 'woocommerce' ),
|
||||
'AZ' => __( 'Azerbaijan', 'woocommerce' ),
|
||||
'BS' => __( 'Bahamas', 'woocommerce' ),
|
||||
'BH' => __( 'Bahrain', 'woocommerce' ),
|
||||
'BD' => __( 'Bangladesh', 'woocommerce' ),
|
||||
'BB' => __( 'Barbados', 'woocommerce' ),
|
||||
'BY' => __( 'Belarus', 'woocommerce' ),
|
||||
'BE' => __( 'Belgium', 'woocommerce' ),
|
||||
'PW' => __( 'Belau', 'woocommerce' ),
|
||||
'BZ' => __( 'Belize', 'woocommerce' ),
|
||||
'BJ' => __( 'Benin', 'woocommerce' ),
|
||||
'BM' => __( 'Bermuda', 'woocommerce' ),
|
||||
'BT' => __( 'Bhutan', 'woocommerce' ),
|
||||
'BO' => __( 'Bolivia', 'woocommerce' ),
|
||||
'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'woocommerce' ),
|
||||
'BA' => __( 'Bosnia and Herzegovina', 'woocommerce' ),
|
||||
'BW' => __( 'Botswana', 'woocommerce' ),
|
||||
'BV' => __( 'Bouvet Island', 'woocommerce' ),
|
||||
'BR' => __( 'Brazil', 'woocommerce' ),
|
||||
'IO' => __( 'British Indian Ocean Territory', 'woocommerce' ),
|
||||
'VG' => __( 'British Virgin Islands', 'woocommerce' ),
|
||||
'BN' => __( 'Brunei', 'woocommerce' ),
|
||||
'BG' => __( 'Bulgaria', 'woocommerce' ),
|
||||
'BF' => __( 'Burkina Faso', 'woocommerce' ),
|
||||
'BI' => __( 'Burundi', 'woocommerce' ),
|
||||
'KH' => __( 'Cambodia', 'woocommerce' ),
|
||||
'CM' => __( 'Cameroon', 'woocommerce' ),
|
||||
'CA' => __( 'Canada', 'woocommerce' ),
|
||||
'CV' => __( 'Cape Verde', 'woocommerce' ),
|
||||
'KY' => __( 'Cayman Islands', 'woocommerce' ),
|
||||
'CF' => __( 'Central African Republic', 'woocommerce' ),
|
||||
'TD' => __( 'Chad', 'woocommerce' ),
|
||||
'CL' => __( 'Chile', 'woocommerce' ),
|
||||
'CN' => __( 'China', 'woocommerce' ),
|
||||
'CX' => __( 'Christmas Island', 'woocommerce' ),
|
||||
'CC' => __( 'Cocos (Keeling) Islands', 'woocommerce' ),
|
||||
'CO' => __( 'Colombia', 'woocommerce' ),
|
||||
'KM' => __( 'Comoros', 'woocommerce' ),
|
||||
'CG' => __( 'Congo (Brazzaville)', 'woocommerce' ),
|
||||
'CD' => __( 'Congo (Kinshasa)', 'woocommerce' ),
|
||||
'CK' => __( 'Cook Islands', 'woocommerce' ),
|
||||
'CR' => __( 'Costa Rica', 'woocommerce' ),
|
||||
'HR' => __( 'Croatia', 'woocommerce' ),
|
||||
'CU' => __( 'Cuba', 'woocommerce' ),
|
||||
'CW' => __( 'CuraÇao', 'woocommerce' ),
|
||||
'CY' => __( 'Cyprus', 'woocommerce' ),
|
||||
'CZ' => __( 'Czech Republic', 'woocommerce' ),
|
||||
'DK' => __( 'Denmark', 'woocommerce' ),
|
||||
'DJ' => __( 'Djibouti', 'woocommerce' ),
|
||||
'DM' => __( 'Dominica', 'woocommerce' ),
|
||||
'DO' => __( 'Dominican Republic', 'woocommerce' ),
|
||||
'EC' => __( 'Ecuador', 'woocommerce' ),
|
||||
'EG' => __( 'Egypt', 'woocommerce' ),
|
||||
'SV' => __( 'El Salvador', 'woocommerce' ),
|
||||
'GQ' => __( 'Equatorial Guinea', 'woocommerce' ),
|
||||
'ER' => __( 'Eritrea', 'woocommerce' ),
|
||||
'EE' => __( 'Estonia', 'woocommerce' ),
|
||||
'ET' => __( 'Ethiopia', 'woocommerce' ),
|
||||
'FK' => __( 'Falkland Islands', 'woocommerce' ),
|
||||
'FO' => __( 'Faroe Islands', 'woocommerce' ),
|
||||
'FJ' => __( 'Fiji', 'woocommerce' ),
|
||||
'FI' => __( 'Finland', 'woocommerce' ),
|
||||
'FR' => __( 'France', 'woocommerce' ),
|
||||
'GF' => __( 'French Guiana', 'woocommerce' ),
|
||||
'PF' => __( 'French Polynesia', 'woocommerce' ),
|
||||
'TF' => __( 'French Southern Territories', 'woocommerce' ),
|
||||
'GA' => __( 'Gabon', 'woocommerce' ),
|
||||
'GM' => __( 'Gambia', 'woocommerce' ),
|
||||
'GE' => __( 'Georgia', 'woocommerce' ),
|
||||
'DE' => __( 'Germany', 'woocommerce' ),
|
||||
'GH' => __( 'Ghana', 'woocommerce' ),
|
||||
'GI' => __( 'Gibraltar', 'woocommerce' ),
|
||||
'GR' => __( 'Greece', 'woocommerce' ),
|
||||
'GL' => __( 'Greenland', 'woocommerce' ),
|
||||
'GD' => __( 'Grenada', 'woocommerce' ),
|
||||
'GP' => __( 'Guadeloupe', 'woocommerce' ),
|
||||
'GT' => __( 'Guatemala', 'woocommerce' ),
|
||||
'GG' => __( 'Guernsey', 'woocommerce' ),
|
||||
'GN' => __( 'Guinea', 'woocommerce' ),
|
||||
'GW' => __( 'Guinea-Bissau', 'woocommerce' ),
|
||||
'GY' => __( 'Guyana', 'woocommerce' ),
|
||||
'HT' => __( 'Haiti', 'woocommerce' ),
|
||||
'HM' => __( 'Heard Island and McDonald Islands', 'woocommerce' ),
|
||||
'HN' => __( 'Honduras', 'woocommerce' ),
|
||||
'HK' => __( 'Hong Kong', 'woocommerce' ),
|
||||
'HU' => __( 'Hungary', 'woocommerce' ),
|
||||
'IS' => __( 'Iceland', 'woocommerce' ),
|
||||
'IN' => __( 'India', 'woocommerce' ),
|
||||
'ID' => __( 'Indonesia', 'woocommerce' ),
|
||||
'IR' => __( 'Iran', 'woocommerce' ),
|
||||
'IQ' => __( 'Iraq', 'woocommerce' ),
|
||||
'IE' => __( 'Republic of Ireland', 'woocommerce' ),
|
||||
'IM' => __( 'Isle of Man', 'woocommerce' ),
|
||||
'IL' => __( 'Israel', 'woocommerce' ),
|
||||
'IT' => __( 'Italy', 'woocommerce' ),
|
||||
'CI' => __( 'Ivory Coast', 'woocommerce' ),
|
||||
'JM' => __( 'Jamaica', 'woocommerce' ),
|
||||
'JP' => __( 'Japan', 'woocommerce' ),
|
||||
'JE' => __( 'Jersey', 'woocommerce' ),
|
||||
'JO' => __( 'Jordan', 'woocommerce' ),
|
||||
'KZ' => __( 'Kazakhstan', 'woocommerce' ),
|
||||
'KE' => __( 'Kenya', 'woocommerce' ),
|
||||
'KI' => __( 'Kiribati', 'woocommerce' ),
|
||||
'KW' => __( 'Kuwait', 'woocommerce' ),
|
||||
'KG' => __( 'Kyrgyzstan', 'woocommerce' ),
|
||||
'LA' => __( 'Laos', 'woocommerce' ),
|
||||
'LV' => __( 'Latvia', 'woocommerce' ),
|
||||
'LB' => __( 'Lebanon', 'woocommerce' ),
|
||||
'LS' => __( 'Lesotho', 'woocommerce' ),
|
||||
'LR' => __( 'Liberia', 'woocommerce' ),
|
||||
'LY' => __( 'Libya', 'woocommerce' ),
|
||||
'LI' => __( 'Liechtenstein', 'woocommerce' ),
|
||||
'LT' => __( 'Lithuania', 'woocommerce' ),
|
||||
'LU' => __( 'Luxembourg', 'woocommerce' ),
|
||||
'MO' => __( 'Macao S.A.R., China', 'woocommerce' ),
|
||||
'MK' => __( 'Macedonia', 'woocommerce' ),
|
||||
'MG' => __( 'Madagascar', 'woocommerce' ),
|
||||
'MW' => __( 'Malawi', 'woocommerce' ),
|
||||
'MY' => __( 'Malaysia', 'woocommerce' ),
|
||||
'MV' => __( 'Maldives', 'woocommerce' ),
|
||||
'ML' => __( 'Mali', 'woocommerce' ),
|
||||
'MT' => __( 'Malta', 'woocommerce' ),
|
||||
'MH' => __( 'Marshall Islands', 'woocommerce' ),
|
||||
'MQ' => __( 'Martinique', 'woocommerce' ),
|
||||
'MR' => __( 'Mauritania', 'woocommerce' ),
|
||||
'MU' => __( 'Mauritius', 'woocommerce' ),
|
||||
'YT' => __( 'Mayotte', 'woocommerce' ),
|
||||
'MX' => __( 'Mexico', 'woocommerce' ),
|
||||
'FM' => __( 'Micronesia', 'woocommerce' ),
|
||||
'MD' => __( 'Moldova', 'woocommerce' ),
|
||||
'MC' => __( 'Monaco', 'woocommerce' ),
|
||||
'MN' => __( 'Mongolia', 'woocommerce' ),
|
||||
'ME' => __( 'Montenegro', 'woocommerce' ),
|
||||
'MS' => __( 'Montserrat', 'woocommerce' ),
|
||||
'MA' => __( 'Morocco', 'woocommerce' ),
|
||||
'MZ' => __( 'Mozambique', 'woocommerce' ),
|
||||
'MM' => __( 'Myanmar', 'woocommerce' ),
|
||||
'NA' => __( 'Namibia', 'woocommerce' ),
|
||||
'NR' => __( 'Nauru', 'woocommerce' ),
|
||||
'NP' => __( 'Nepal', 'woocommerce' ),
|
||||
'NL' => __( 'Netherlands', 'woocommerce' ),
|
||||
'AN' => __( 'Netherlands Antilles', 'woocommerce' ),
|
||||
'NC' => __( 'New Caledonia', 'woocommerce' ),
|
||||
'NZ' => __( 'New Zealand', 'woocommerce' ),
|
||||
'NI' => __( 'Nicaragua', 'woocommerce' ),
|
||||
'NE' => __( 'Niger', 'woocommerce' ),
|
||||
'NG' => __( 'Nigeria', 'woocommerce' ),
|
||||
'NU' => __( 'Niue', 'woocommerce' ),
|
||||
'NF' => __( 'Norfolk Island', 'woocommerce' ),
|
||||
'KP' => __( 'North Korea', 'woocommerce' ),
|
||||
'NO' => __( 'Norway', 'woocommerce' ),
|
||||
'OM' => __( 'Oman', 'woocommerce' ),
|
||||
'PK' => __( 'Pakistan', 'woocommerce' ),
|
||||
'PS' => __( 'Palestinian Territory', 'woocommerce' ),
|
||||
'PA' => __( 'Panama', 'woocommerce' ),
|
||||
'PG' => __( 'Papua New Guinea', 'woocommerce' ),
|
||||
'PY' => __( 'Paraguay', 'woocommerce' ),
|
||||
'PE' => __( 'Peru', 'woocommerce' ),
|
||||
'PH' => __( 'Philippines', 'woocommerce' ),
|
||||
'PN' => __( 'Pitcairn', 'woocommerce' ),
|
||||
'PL' => __( 'Poland', 'woocommerce' ),
|
||||
'PT' => __( 'Portugal', 'woocommerce' ),
|
||||
'QA' => __( 'Qatar', 'woocommerce' ),
|
||||
'RE' => __( 'Reunion', 'woocommerce' ),
|
||||
'RO' => __( 'Romania', 'woocommerce' ),
|
||||
'RU' => __( 'Russia', 'woocommerce' ),
|
||||
'RW' => __( 'Rwanda', 'woocommerce' ),
|
||||
'BL' => __( 'Saint Barthélemy', 'woocommerce' ),
|
||||
'SH' => __( 'Saint Helena', 'woocommerce' ),
|
||||
'KN' => __( 'Saint Kitts and Nevis', 'woocommerce' ),
|
||||
'LC' => __( 'Saint Lucia', 'woocommerce' ),
|
||||
'MF' => __( 'Saint Martin (French part)', 'woocommerce' ),
|
||||
'SX' => __( 'Saint Martin (Dutch part)', 'woocommerce' ),
|
||||
'PM' => __( 'Saint Pierre and Miquelon', 'woocommerce' ),
|
||||
'VC' => __( 'Saint Vincent and the Grenadines', 'woocommerce' ),
|
||||
'SM' => __( 'San Marino', 'woocommerce' ),
|
||||
'ST' => __( 'São Tomé and Príncipe', 'woocommerce' ),
|
||||
'SA' => __( 'Saudi Arabia', 'woocommerce' ),
|
||||
'SN' => __( 'Senegal', 'woocommerce' ),
|
||||
'RS' => __( 'Serbia', 'woocommerce' ),
|
||||
'SC' => __( 'Seychelles', 'woocommerce' ),
|
||||
'SL' => __( 'Sierra Leone', 'woocommerce' ),
|
||||
'SG' => __( 'Singapore', 'woocommerce' ),
|
||||
'SK' => __( 'Slovakia', 'woocommerce' ),
|
||||
'SI' => __( 'Slovenia', 'woocommerce' ),
|
||||
'SB' => __( 'Solomon Islands', 'woocommerce' ),
|
||||
'SO' => __( 'Somalia', 'woocommerce' ),
|
||||
'ZA' => __( 'South Africa', 'woocommerce' ),
|
||||
'GS' => __( 'South Georgia/Sandwich Islands', 'woocommerce' ),
|
||||
'KR' => __( 'South Korea', 'woocommerce' ),
|
||||
'SS' => __( 'South Sudan', 'woocommerce' ),
|
||||
'ES' => __( 'Spain', 'woocommerce' ),
|
||||
'LK' => __( 'Sri Lanka', 'woocommerce' ),
|
||||
'SD' => __( 'Sudan', 'woocommerce' ),
|
||||
'SR' => __( 'Suriname', 'woocommerce' ),
|
||||
'SJ' => __( 'Svalbard and Jan Mayen', 'woocommerce' ),
|
||||
'SZ' => __( 'Swaziland', 'woocommerce' ),
|
||||
'SE' => __( 'Sweden', 'woocommerce' ),
|
||||
'CH' => __( 'Switzerland', 'woocommerce' ),
|
||||
'SY' => __( 'Syria', 'woocommerce' ),
|
||||
'TW' => __( 'Taiwan', 'woocommerce' ),
|
||||
'TJ' => __( 'Tajikistan', 'woocommerce' ),
|
||||
'TZ' => __( 'Tanzania', 'woocommerce' ),
|
||||
'TH' => __( 'Thailand', 'woocommerce' ),
|
||||
'TL' => __( 'Timor-Leste', 'woocommerce' ),
|
||||
'TG' => __( 'Togo', 'woocommerce' ),
|
||||
'TK' => __( 'Tokelau', 'woocommerce' ),
|
||||
'TO' => __( 'Tonga', 'woocommerce' ),
|
||||
'TT' => __( 'Trinidad and Tobago', 'woocommerce' ),
|
||||
'TN' => __( 'Tunisia', 'woocommerce' ),
|
||||
'TR' => __( 'Turkey', 'woocommerce' ),
|
||||
'TM' => __( 'Turkmenistan', 'woocommerce' ),
|
||||
'TC' => __( 'Turks and Caicos Islands', 'woocommerce' ),
|
||||
'TV' => __( 'Tuvalu', 'woocommerce' ),
|
||||
'UG' => __( 'Uganda', 'woocommerce' ),
|
||||
'UA' => __( 'Ukraine', 'woocommerce' ),
|
||||
'AE' => __( 'United Arab Emirates', 'woocommerce' ),
|
||||
'GB' => __( 'United Kingdom (UK)', 'woocommerce' ),
|
||||
'US' => __( 'United States (US)', 'woocommerce' ),
|
||||
'UY' => __( 'Uruguay', 'woocommerce' ),
|
||||
'UZ' => __( 'Uzbekistan', 'woocommerce' ),
|
||||
'VU' => __( 'Vanuatu', 'woocommerce' ),
|
||||
'VA' => __( 'Vatican', 'woocommerce' ),
|
||||
'VE' => __( 'Venezuela', 'woocommerce' ),
|
||||
'VN' => __( 'Vietnam', 'woocommerce' ),
|
||||
'WF' => __( 'Wallis and Futuna', 'woocommerce' ),
|
||||
'EH' => __( 'Western Sahara', 'woocommerce' ),
|
||||
'WS' => __( 'Western Samoa', 'woocommerce' ),
|
||||
'YE' => __( 'Yemen', 'woocommerce' ),
|
||||
'ZM' => __( 'Zambia', 'woocommerce' ),
|
||||
'ZW' => __( 'Zimbabwe', 'woocommerce' ),
|
||||
'EU' => __( 'European Union', 'woocommerce' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_countries' ) ) {
|
||||
/**
|
||||
* wcj_get_currency_countries.
|
||||
*
|
||||
* 158 currencies.
|
||||
* Three-letter currency code (ISO 4217) => Two-letter countries codes (ISO 3166-1 alpha-2).
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_get_currency_countries() {
|
||||
return array(
|
||||
'AFN' => array( 'AF' ),
|
||||
'ALL' => array( 'AL' ),
|
||||
'DZD' => array( 'DZ' ),
|
||||
'USD' => array( 'US', 'AS', 'IO', 'GU', 'MH', 'FM', 'MP', 'PW', 'PR', 'TC', 'UM', 'VI' ),
|
||||
'EUR' => array( 'AD', 'AT', 'BE', 'CY', 'EE', 'FI', 'FR', 'GF', 'TF', 'DE', 'GR', 'GP', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'MQ', 'YT', 'MC', 'ME', 'NL', 'PT', 'RE', 'PM', 'SM', 'SK', 'SI', 'ES' ),
|
||||
'AOA' => array( 'AO' ),
|
||||
'XCD' => array( 'KN', 'AI', 'AQ', 'AG', 'DM', 'GD', 'MS', 'LC', 'VC' ),
|
||||
'ARS' => array( 'AR' ),
|
||||
'AMD' => array( 'AM' ),
|
||||
'AWG' => array( 'AW' ),
|
||||
'AUD' => array( 'AU', 'CX', 'CC', 'HM', 'KI', 'NR', 'NF', 'TV' ),
|
||||
'AZN' => array( 'AZ' ),
|
||||
'BSD' => array( 'BS' ),
|
||||
'BHD' => array( 'BH' ),
|
||||
'BDT' => array( 'BD' ),
|
||||
'BBD' => array( 'BB' ),
|
||||
'BYN' => array( 'BY' ),
|
||||
'BZD' => array( 'BZ' ),
|
||||
'XOF' => array( 'SN', 'BJ', 'BF', 'ML', 'NE', 'TG' ),
|
||||
'BMD' => array( 'BM' ),
|
||||
'BTN' => array( 'BT' ),
|
||||
'BOB' => array( 'BO' ),
|
||||
'BAM' => array( 'BA' ),
|
||||
'BWP' => array( 'BW' ),
|
||||
'NOK' => array( 'NO', 'BV', 'SJ' ),
|
||||
'BRL' => array( 'BR' ),
|
||||
'BND' => array( 'BN' ),
|
||||
'BGN' => array( 'BG' ),
|
||||
'BIF' => array( 'BI' ),
|
||||
'KHR' => array( 'KH' ),
|
||||
'XAF' => array( 'CF', 'CM', 'TD', 'CG', 'GQ', 'GA' ),
|
||||
'CAD' => array( 'CA' ),
|
||||
'CVE' => array( 'CV' ),
|
||||
'KYD' => array( 'KY' ),
|
||||
'CLP' => array( 'CL' ),
|
||||
'CNY' => array( 'CN' ),
|
||||
'RMB' => array( 'CN' ),
|
||||
'HKD' => array( 'HK' ),
|
||||
'COP' => array( 'CO' ),
|
||||
'KMF' => array( 'KM' ),
|
||||
'CDF' => array( 'CD' ),
|
||||
'NZD' => array( 'NZ', 'CK', 'NU', 'PN', 'TK' ),
|
||||
'CRC' => array( 'CR' ),
|
||||
'HRK' => array( 'HR' ),
|
||||
'CUP' => array( 'CU' ),
|
||||
'CUC' => array( 'CU' ),
|
||||
'CZK' => array( 'CZ' ),
|
||||
'DKK' => array( 'DK', 'FO', 'GL' ),
|
||||
'DJF' => array( 'DJ' ),
|
||||
'DOP' => array( 'DO' ),
|
||||
'ECS' => array( 'EC' ),
|
||||
'EGP' => array( 'EG' ),
|
||||
'SVC' => array( 'SV' ),
|
||||
'ERN' => array( 'ER' ),
|
||||
'ETB' => array( 'ET' ),
|
||||
'FKP' => array( 'FK' ),
|
||||
'FJD' => array( 'FJ' ),
|
||||
'GMD' => array( 'GM' ),
|
||||
'GEL' => array( 'GE' ),
|
||||
'GHS' => array( 'GH' ),
|
||||
'GIP' => array( 'GI' ),
|
||||
'QTQ' => array( 'GT' ),
|
||||
'GTQ' => array( 'GT' ),
|
||||
'GGP' => array( 'GG' ),
|
||||
'GNF' => array( 'GN' ),
|
||||
'GWP' => array( 'GW' ),
|
||||
'GYD' => array( 'GY' ),
|
||||
'HTG' => array( 'HT' ),
|
||||
'HNL' => array( 'HN' ),
|
||||
'HUF' => array( 'HU' ),
|
||||
'ISK' => array( 'IS' ),
|
||||
'INR' => array( 'IN' ),
|
||||
'IDR' => array( 'ID' ),
|
||||
'IRR' => array( 'IR' ),
|
||||
'IQD' => array( 'IQ' ),
|
||||
'GBP' => array( 'GB', 'IM', 'JE', 'GS' ),
|
||||
'ILS' => array( 'IL' ),
|
||||
'JMD' => array( 'JM' ),
|
||||
'JPY' => array( 'JP' ),
|
||||
'JOD' => array( 'JO' ),
|
||||
'KZT' => array( 'KZ' ),
|
||||
'KES' => array( 'KE' ),
|
||||
'KPW' => array( 'KP' ),
|
||||
'KRW' => array( 'KR' ),
|
||||
'KWD' => array( 'KW' ),
|
||||
'KGS' => array( 'KG' ),
|
||||
'LAK' => array( 'LA' ),
|
||||
'KIP' => array( 'LA' ),
|
||||
'LBP' => array( 'LB' ),
|
||||
'LSL' => array( 'LS' ),
|
||||
'LRD' => array( 'LR' ),
|
||||
'LYD' => array( 'LY' ),
|
||||
'CHF' => array( 'CH', 'LI' ),
|
||||
'MKD' => array( 'MK' ),
|
||||
'MGF' => array( 'MG' ),
|
||||
'MGA' => array( 'MG' ),
|
||||
'MWK' => array( 'MW' ),
|
||||
'MYR' => array( 'MY' ),
|
||||
'MVR' => array( 'MV' ),
|
||||
'MRO' => array( 'MR' ),
|
||||
'MUR' => array( 'MU' ),
|
||||
'MXN' => array( 'MX' ),
|
||||
'MDL' => array( 'MD' ),
|
||||
'MNT' => array( 'MN' ),
|
||||
'MAD' => array( 'MA', 'EH' ),
|
||||
'MZN' => array( 'MZ' ),
|
||||
'MZM' => array( 'MZ' ),
|
||||
'MMK' => array( 'MM' ),
|
||||
'NAD' => array( 'NA' ),
|
||||
'NPR' => array( 'NP' ),
|
||||
'ANG' => array( 'AN' ),
|
||||
'XPF' => array( 'NC', 'WF' ),
|
||||
'NIO' => array( 'NI' ),
|
||||
'NGN' => array( 'NG' ),
|
||||
'OMR' => array( 'OM' ),
|
||||
'PKR' => array( 'PK' ),
|
||||
'PAB' => array( 'PA' ),
|
||||
'PGK' => array( 'PG' ),
|
||||
'PYG' => array( 'PY' ),
|
||||
'PEN' => array( 'PE' ),
|
||||
'PHP' => array( 'PH' ),
|
||||
'PLN' => array( 'PL' ),
|
||||
'QAR' => array( 'QA' ),
|
||||
'RON' => array( 'RO' ),
|
||||
'RUB' => array( 'RU' ),
|
||||
'RWF' => array( 'RW' ),
|
||||
'SHP' => array( 'SH' ),
|
||||
'WST' => array( 'WS' ),
|
||||
'STD' => array( 'ST' ),
|
||||
'SAR' => array( 'SA' ),
|
||||
'RSD' => array( 'RS' ),
|
||||
'SCR' => array( 'SC' ),
|
||||
'SLL' => array( 'SL' ),
|
||||
'SGD' => array( 'SG' ),
|
||||
'SBD' => array( 'SB' ),
|
||||
'SOS' => array( 'SO' ),
|
||||
'ZAR' => array( 'ZA' ),
|
||||
'SSP' => array( 'SS' ),
|
||||
'LKR' => array( 'LK' ),
|
||||
'SDG' => array( 'SD' ),
|
||||
'SRD' => array( 'SR' ),
|
||||
'SZL' => array( 'SZ' ),
|
||||
'SEK' => array( 'SE' ),
|
||||
'SYP' => array( 'SY' ),
|
||||
'TWD' => array( 'TW' ),
|
||||
'TJS' => array( 'TJ' ),
|
||||
'TZS' => array( 'TZ' ),
|
||||
'THB' => array( 'TH' ),
|
||||
'TOP' => array( 'TO' ),
|
||||
'TTD' => array( 'TT' ),
|
||||
'TND' => array( 'TN' ),
|
||||
'TRY' => array( 'TR' ),
|
||||
'TMT' => array( 'TM' ),
|
||||
'TMM' => array( 'TM' ),
|
||||
'UGX' => array( 'UG' ),
|
||||
'UAH' => array( 'UA' ),
|
||||
'AED' => array( 'AE' ),
|
||||
'UYU' => array( 'UY' ),
|
||||
'UZS' => array( 'UZ' ),
|
||||
'VUV' => array( 'VU' ),
|
||||
'VEF' => array( 'VE' ),
|
||||
'VND' => array( 'VN' ),
|
||||
'YER' => array( 'YE' ),
|
||||
'ZMW' => array( 'ZM' ),
|
||||
'ZMK' => array( 'ZM' ),
|
||||
'ZWD' => array( 'ZW' ),
|
||||
'GQE' => array( 'CF' ),
|
||||
'MOP' => array( 'MO' ),
|
||||
// Former currencies
|
||||
'LTL' => array( 'LT' ),
|
||||
'LVL' => array( 'LV' ),
|
||||
'EEK' => array( 'EE' ),
|
||||
'SKK' => array( 'SK' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Crons
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
* @author Algoritmika Ltd.
|
||||
* @todo use all functions where applicable
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_crons_get_all_intervals' ) ) {
|
||||
/**
|
||||
* wcj_crons_get_all_intervals.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_crons_get_all_intervals( $action = '', $skip_intervals = array() ) {
|
||||
if ( '' === $action ) {
|
||||
$action = __( 'Update', 'woocommerce-jetpack' );
|
||||
}
|
||||
$return = array(
|
||||
'minutely' => sprintf( __( '%s every minute', 'woocommerce-jetpack' ), $action ),
|
||||
'minute_5' => sprintf( __( '%s every 5 minutes', 'woocommerce-jetpack' ), $action ),
|
||||
'minute_15' => sprintf( __( '%s every 15 minutes', 'woocommerce-jetpack' ), $action ),
|
||||
'minute_30' => sprintf( __( '%s every 30 minutes', 'woocommerce-jetpack' ), $action ),
|
||||
'hourly' => sprintf( __( '%s hourly', 'woocommerce-jetpack' ), $action ),
|
||||
'twicedaily' => sprintf( __( '%s twice daily', 'woocommerce-jetpack' ), $action ),
|
||||
'daily' => sprintf( __( '%s daily', 'woocommerce-jetpack' ), $action ),
|
||||
'weekly' => sprintf( __( '%s weekly', 'woocommerce-jetpack' ), $action ),
|
||||
);
|
||||
if ( ! empty( $skip_intervals ) ) {
|
||||
foreach ( $skip_intervals as $skip_interval ) {
|
||||
unset( $return[ $skip_interval ] );
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_crons_schedule_the_events' ) ) {
|
||||
/**
|
||||
* wcj_crons_schedule_the_events.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_crons_schedule_the_events( $event_hook, $selected_interval ) {
|
||||
$intervals = array_keys( wcj_crons_get_all_intervals() );
|
||||
foreach ( $intervals as $interval ) {
|
||||
$event_timestamp = wp_next_scheduled( $event_hook, array( $interval ) );
|
||||
if ( $selected_interval === $interval ) {
|
||||
update_option( $event_hook . '_time', $event_timestamp );
|
||||
}
|
||||
if ( ! $event_timestamp && $selected_interval === $interval ) {
|
||||
wp_schedule_event( time(), $selected_interval, $event_hook, array( $selected_interval ) );
|
||||
} elseif ( $event_timestamp && $selected_interval !== $interval ) {
|
||||
wp_unschedule_event( $event_timestamp, $event_hook, array( $interval ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_crons_get_next_event_time_message' ) ) {
|
||||
/**
|
||||
* wcj_crons_get_next_event_time_message.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
* @todo (maybe) move to "date-time" functions
|
||||
*/
|
||||
function wcj_crons_get_next_event_time_message( $time_option_name ) {
|
||||
if ( '' != get_option( $time_option_name, '' ) ) {
|
||||
$scheduled_time_diff = get_option( $time_option_name, '' ) - time();
|
||||
if ( $scheduled_time_diff > 60 ) {
|
||||
return '<br><em>' . sprintf( __( '%s till next run.', 'woocommerce-jetpack' ), human_time_diff( 0, $scheduled_time_diff ) ) . '</em>';
|
||||
} elseif ( $scheduled_time_diff > 0 ) {
|
||||
return '<br><em>' . sprintf( __( '%s seconds till next run.', 'woocommerce-jetpack' ), $scheduled_time_diff ) . '</em>';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_crons_add_custom_intervals' ) ) {
|
||||
/**
|
||||
* wcj_crons_add_custom_intervals.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_crons_add_custom_intervals( $schedules ) {
|
||||
$schedules['weekly'] = array(
|
||||
'interval' => 604800,
|
||||
'display' => __( 'Once weekly', 'woocommerce-jetpack' )
|
||||
);
|
||||
$schedules['minute_30'] = array(
|
||||
'interval' => 1800,
|
||||
'display' => __( 'Once every 30 minutes', 'woocommerce-jetpack' )
|
||||
);
|
||||
$schedules['minute_15'] = array(
|
||||
'interval' => 900,
|
||||
'display' => __( 'Once every 15 minutes', 'woocommerce-jetpack' )
|
||||
);
|
||||
$schedules['minute_5'] = array(
|
||||
'interval' => 300,
|
||||
'display' => __( 'Once every 5 minutes', 'woocommerce-jetpack' )
|
||||
);
|
||||
$schedules['minutely'] = array(
|
||||
'interval' => 60,
|
||||
'display' => __( 'Once a minute', 'woocommerce-jetpack' )
|
||||
);
|
||||
return $schedules;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Currencies
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currencies_array' ) ) {
|
||||
/**
|
||||
* wcj_get_currencies_array.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @todo clean up / rewrite
|
||||
*/
|
||||
function wcj_get_currencies_array() {
|
||||
return array(
|
||||
array( 'code' => 'AED', 'symbol' => 'د.إ', 'name' => __( 'United Arab Emirates Dirham', 'woocommerce' ) ),
|
||||
array( 'code' => 'AFN', 'symbol' => 'AFN', 'name' => __( 'Afghan afghani', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ALL', 'symbol' => 'ALL', 'name' => __( 'Albanian lek', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'AMD', 'symbol' => 'AMD', 'name' => __( 'Armenian dram', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ANG', 'symbol' => 'ANG', 'name' => __( 'Netherlands Antillean gulden', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'AOA', 'symbol' => 'AOA', 'name' => __( 'Angolan kwanza', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ARS', 'symbol' => '$', 'name' => __( 'Argentine Peso', 'woocommerce' ) ),
|
||||
array( 'code' => 'AUD', 'symbol' => '$', 'name' => __( 'Australian Dollars', 'woocommerce' ) ),
|
||||
array( 'code' => 'AWG', 'symbol' => 'AWG', 'name' => __( 'Aruban florin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'AZN', 'symbol' => 'AZN', 'name' => __( 'Azerbaijani manat', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BAM', 'symbol' => 'BAM', 'name' => __( 'Bosnia and Herzegovina konvertibilna marka', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BBD', 'symbol' => 'BBD', 'name' => __( 'Barbadian dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BDT', 'symbol' => '৳ ', 'name' => __( 'Bangladeshi Taka', 'woocommerce' ) ),
|
||||
array( 'code' => 'BGN', 'symbol' => 'лв.', 'name' => __( 'Bulgarian Lev', 'woocommerce' ) ),
|
||||
array( 'code' => 'BHD', 'symbol' => 'BHD', 'name' => __( 'Bahraini dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BIF', 'symbol' => 'BIF', 'name' => __( 'Burundi franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BYN', 'symbol' => 'BYN', 'name' => __( 'Belarusian ruble', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BND', 'symbol' => 'BND', 'name' => __( 'Brunei dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BOB', 'symbol' => 'BOB', 'name' => __( 'Bolivian boliviano', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BRL', 'symbol' => 'R$', 'name' => __( 'Brazilian Real', 'woocommerce' ) ),
|
||||
array( 'code' => 'BSD', 'symbol' => 'BSD', 'name' => __( 'Bahamian dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BTN', 'symbol' => 'BTN', 'name' => __( 'Bhutanese ngultrum', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BWP', 'symbol' => 'BWP', 'name' => __( 'Botswana pula', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BZD', 'symbol' => 'BZD', 'name' => __( 'Belize dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'CAD', 'symbol' => '$', 'name' => __( 'Canadian Dollars', 'woocommerce' ) ),
|
||||
array( 'code' => 'CDF', 'symbol' => 'CDF', 'name' => __( 'Congolese franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'CHF', 'symbol' => 'CHF', 'name' => __( 'Swiss Franc', 'woocommerce' ) ),
|
||||
array( 'code' => 'CLP', 'symbol' => '$', 'name' => __( 'Chilean Peso', 'woocommerce' ) ),
|
||||
array( 'code' => 'CNY', 'symbol' => '¥', 'name' => __( 'Chinese Yuan', 'woocommerce' ) ),
|
||||
array( 'code' => 'COP', 'symbol' => '$', 'name' => __( 'Colombian Peso', 'woocommerce' ) ),
|
||||
array( 'code' => 'CRC', 'symbol' => 'CRC', 'name' => __( 'Costa Rican colon', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'CUC', 'symbol' => 'CUC', 'name' => __( 'Cuban peso', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'CVE', 'symbol' => 'CVE', 'name' => __( 'Cape Verdean escudo', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'CZK', 'symbol' => 'Kč', 'name' => __( 'Czech Koruna', 'woocommerce' ) ),
|
||||
array( 'code' => 'DJF', 'symbol' => 'DJF', 'name' => __( 'Djiboutian franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'DKK', 'symbol' => 'DKK', 'name' => __( 'Danish Krone', 'woocommerce' ) ),
|
||||
array( 'code' => 'DOP', 'symbol' => 'RD$', 'name' => __( 'Dominican Peso', 'woocommerce' ) ),
|
||||
array( 'code' => 'DZD', 'symbol' => 'DZD', 'name' => __( 'Algerian dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'EEK', 'symbol' => 'EEK', 'name' => __( 'Estonian kroon', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'EGP', 'symbol' => 'EGP', 'name' => __( 'Egyptian Pound', 'woocommerce' ) ),
|
||||
array( 'code' => 'ERN', 'symbol' => 'ERN', 'name' => __( 'Eritrean nakfa', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ETB', 'symbol' => 'ETB', 'name' => __( 'Ethiopian birr', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'EUR', 'symbol' => '€', 'name' => __( 'Euros', 'woocommerce' ) ),
|
||||
array( 'code' => 'FJD', 'symbol' => 'FJD', 'name' => __( 'Fijian dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'FKP', 'symbol' => 'FKP', 'name' => __( 'Falkland Islands pound', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GBP', 'symbol' => '£', 'name' => __( 'Pounds Sterling', 'woocommerce' ) ),
|
||||
array( 'code' => 'GEL', 'symbol' => 'GEL', 'name' => __( 'Georgian lari', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GHS', 'symbol' => 'GHS', 'name' => __( 'Ghanaian cedi', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GIP', 'symbol' => 'GIP', 'name' => __( 'Gibraltar pound', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GYD', 'symbol' => 'GYD', 'name' => __( 'Guyanese dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GMD', 'symbol' => 'GMD', 'name' => __( 'Gambian dalasi', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GNF', 'symbol' => 'GNF', 'name' => __( 'Guinean franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GQE', 'symbol' => 'GQE', 'name' => __( 'Central African CFA franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GTQ', 'symbol' => 'GTQ', 'name' => __( 'Guatemalan quetzal', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'HKD', 'symbol' => '$', 'name' => __( 'Hong Kong Dollar', 'woocommerce' ) ),
|
||||
array( 'code' => 'HNL', 'symbol' => 'HNL', 'name' => __( 'Honduran lempira', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'HRK', 'symbol' => 'Kn', 'name' => __( 'Croatia kuna', 'woocommerce' ) ),
|
||||
array( 'code' => 'HTG', 'symbol' => 'HTG', 'name' => __( 'Haitian gourde', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'HUF', 'symbol' => 'Ft', 'name' => __( 'Hungarian Forint', 'woocommerce' ) ),
|
||||
array( 'code' => 'IDR', 'symbol' => 'Rp', 'name' => __( 'Indonesia Rupiah', 'woocommerce' ) ),
|
||||
array( 'code' => 'ILS', 'symbol' => '₪', 'name' => __( 'Israeli Shekel', 'woocommerce' ) ),
|
||||
array( 'code' => 'INR', 'symbol' => '₹', 'name' => __( 'Indian Rupee', 'woocommerce' ) ),
|
||||
array( 'code' => 'IQD', 'symbol' => 'IQD', 'name' => __( 'Iraqi dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'IRR', 'symbol' => 'IRR', 'name' => __( 'Iranian rial', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ISK', 'symbol' => 'Kr.', 'name' => __( 'Icelandic krona', 'woocommerce' ) ),
|
||||
array( 'code' => 'YER', 'symbol' => 'YER', 'name' => __( 'Yemeni rial', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'JMD', 'symbol' => 'JMD', 'name' => __( 'Jamaican dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'JOD', 'symbol' => 'JOD', 'name' => __( 'Jordanian dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'JPY', 'symbol' => '¥', 'name' => __( 'Japanese Yen', 'woocommerce' ) ),
|
||||
array( 'code' => 'KES', 'symbol' => 'KSh', 'name' => __( 'Kenyan shilling', 'woocommerce' ) ),
|
||||
array( 'code' => 'KGS', 'symbol' => 'KGS', 'name' => __( 'Kyrgyzstani som', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KHR', 'symbol' => 'KHR', 'name' => __( 'Cambodian riel', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KIP', 'symbol' => 'KIP', 'name' => __( 'Lao kip', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KYD', 'symbol' => 'KYD', 'name' => __( 'Cayman Islands dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KMF', 'symbol' => 'KMF', 'name' => __( 'Comorian franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KPW', 'symbol' => 'KPW', 'name' => __( 'North Korean won', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KRW', 'symbol' => '₩', 'name' => __( 'South Korean Won', 'woocommerce' ) ),
|
||||
array( 'code' => 'KWD', 'symbol' => 'KWD', 'name' => __( 'Kuwaiti dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KZT', 'symbol' => 'KZT', 'name' => __( 'Kazakhstani tenge', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LAK', 'symbol' => '₭', 'name' => __( 'Lao Kip', 'woocommerce' ) ),
|
||||
array( 'code' => 'LBP', 'symbol' => 'LBP', 'name' => __( 'Lebanese lira', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LYD', 'symbol' => 'LYD', 'name' => __( 'Libyan dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LKR', 'symbol' => 'LKR', 'name' => __( 'Sri Lankan rupee', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LRD', 'symbol' => 'LRD', 'name' => __( 'Liberian dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LSL', 'symbol' => 'LSL', 'name' => __( 'Lesotho loti', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LTL', 'symbol' => 'LTL', 'name' => __( 'Lithuanian litas', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LVL', 'symbol' => 'LVL', 'name' => __( 'Latvian lats', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MAD', 'symbol' => 'MAD', 'name' => __( 'Moroccan dirham', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MDL', 'symbol' => 'MDL', 'name' => __( 'Moldovan leu', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MGA', 'symbol' => 'MGA', 'name' => __( 'Malagasy ariary', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MYR', 'symbol' => 'RM', 'name' => __( 'Malaysian ringgit', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MKD', 'symbol' => 'MKD', 'name' => __( 'Macedonian denar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MMK', 'symbol' => 'MMK', 'name' => __( 'Myanma kyat', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MNT', 'symbol' => 'MNT', 'name' => __( 'Mongolian tugrik', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MOP', 'symbol' => 'MOP', 'name' => __( 'Macanese pataca', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MRO', 'symbol' => 'MRO', 'name' => __( 'Mauritanian ouguiya', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MUR', 'symbol' => 'MUR', 'name' => __( 'Mauritian rupee', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MVR', 'symbol' => 'MVR', 'name' => __( 'Maldivian rufiyaa', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MWK', 'symbol' => 'MWK', 'name' => __( 'Malawian kwacha', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MXN', 'symbol' => '$', 'name' => __( 'Mexican Peso', 'woocommerce' ) ),
|
||||
array( 'code' => 'MYR', 'symbol' => 'RM', 'name' => __( 'Malaysian Ringgits', 'woocommerce' ) ),
|
||||
array( 'code' => 'MZM', 'symbol' => 'MZM', 'name' => __( 'Mozambican metical', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'NAD', 'symbol' => 'NAD', 'name' => __( 'Namibian dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'NGN', 'symbol' => '₦', 'name' => __( 'Nigerian Naira', 'woocommerce' ) ),
|
||||
array( 'code' => 'NIO', 'symbol' => 'NIO', 'name' => __( 'Nicaraguan cordoba', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'NOK', 'symbol' => 'kr', 'name' => __( 'Norwegian Krone', 'woocommerce' ) ),
|
||||
array( 'code' => 'NPR', 'symbol' => '₨', 'name' => __( 'Nepali Rupee', 'woocommerce' ) ),
|
||||
array( 'code' => 'NZD', 'symbol' => '$', 'name' => __( 'New Zealand Dollar', 'woocommerce' ) ),
|
||||
array( 'code' => 'OMR', 'symbol' => 'OMR', 'name' => __( 'Omani rial', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'PAB', 'symbol' => 'PAB', 'name' => __( 'Panamanian balboa', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'PEN', 'symbol' => 'PEN', 'name' => __( 'Peruvian nuevo sol', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'PGK', 'symbol' => 'PGK', 'name' => __( 'Papua New Guinean kina', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'PHP', 'symbol' => '₱', 'name' => __( 'Philippine Pesos', 'woocommerce' ) ),
|
||||
array( 'code' => 'PYG', 'symbol' => 'PYG', 'name' => __( 'Paraguayan guarani', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'PKR', 'symbol' => '₨', 'name' => __( 'Pakistani Rupee', 'woocommerce' ) ),
|
||||
array( 'code' => 'PLN', 'symbol' => 'zł', 'name' => __( 'Polish Zloty', 'woocommerce' ) ),
|
||||
array( 'code' => 'PYG', 'symbol' => '₲', 'name' => __( 'Paraguayan Guaraní', 'woocommerce' ) ),
|
||||
array( 'code' => 'QAR', 'symbol' => 'QAR', 'name' => __( 'Qatari riyal', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'RMB', 'symbol' => '¥', 'name' => __( 'Chinese renminbi', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'RON', 'symbol' => 'lei', 'name' => __( 'Romanian Leu', 'woocommerce' ) ),
|
||||
array( 'code' => 'RSD', 'symbol' => 'RSD', 'name' => __( 'Serbian dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'RUB', 'symbol' => '₽', 'name' => __( 'Russian Ruble', 'woocommerce' ) ),
|
||||
array( 'code' => 'RWF', 'symbol' => 'RWF', 'name' => __( 'Rwandan franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SAR', 'symbol' => 'ر.س', 'name' => __( 'Saudi Riyal', 'woocommerce' ) ),
|
||||
array( 'code' => 'SBD', 'symbol' => 'SBD', 'name' => __( 'Solomon Islands dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SCR', 'symbol' => 'SCR', 'name' => __( 'Seychellois rupee', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SDG', 'symbol' => 'SDG', 'name' => __( 'Sudanese pound', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SEK', 'symbol' => 'kr', 'name' => __( 'Swedish Krona', 'woocommerce' ) ),
|
||||
array( 'code' => 'SGD', 'symbol' => '$', 'name' => __( 'Singapore Dollar', 'woocommerce' ) ),
|
||||
array( 'code' => 'SHP', 'symbol' => 'SHP', 'name' => __( 'Saint Helena pound', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SYP', 'symbol' => 'SYP', 'name' => __( 'Syrian pound', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SKK', 'symbol' => 'SKK', 'name' => __( 'Slovak koruna', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SLL', 'symbol' => 'SLL', 'name' => __( 'Sierra Leonean leone', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SOS', 'symbol' => 'SOS', 'name' => __( 'Somali shilling', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SRD', 'symbol' => 'SRD', 'name' => __( 'Surinamese dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'STD', 'symbol' => 'STD', 'name' => __( 'Sao Tome and Principe dobra', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SZL', 'symbol' => 'SZL', 'name' => __( 'Swazi lilangeni', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'THB', 'symbol' => '฿', 'name' => __( 'Thai Baht', 'woocommerce' ) ),
|
||||
array( 'code' => 'TJS', 'symbol' => 'TJS', 'name' => __( 'Tajikistani somoni', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'TMM', 'symbol' => 'TMM', 'name' => __( 'Turkmen manat', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'TND', 'symbol' => 'TND', 'name' => __( 'Tunisian dinar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'TOP', 'symbol' => 'TOP', 'name' => __( 'Paanga', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'TRY', 'symbol' => '₺', 'name' => __( 'Turkish Lira', 'woocommerce' ) ),
|
||||
array( 'code' => 'TTD', 'symbol' => 'TTD', 'name' => __( 'Trinidad and Tobago dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'TWD', 'symbol' => 'NT$', 'name' => __( 'Taiwan New Dollars', 'woocommerce' ) ),
|
||||
array( 'code' => 'TZS', 'symbol' => 'TZS', 'name' => __( 'Tanzanian shilling', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'UAH', 'symbol' => '₴', 'name' => __( 'Ukrainian Hryvnia', 'woocommerce' ) ),
|
||||
array( 'code' => 'UGX', 'symbol' => 'UGX', 'name' => __( 'Ugandan shilling', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'UYU', 'symbol' => 'UYU', 'name' => __( 'Uruguayan peso', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'USD', 'symbol' => '$', 'name' => __( 'US Dollars', 'woocommerce' ) ),
|
||||
array( 'code' => 'UZS', 'symbol' => 'UZS', 'name' => __( 'Uzbekistani som', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'VEF', 'symbol' => 'VEF', 'name' => __( 'Venezuelan bolivar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'VND', 'symbol' => '₫', 'name' => __( 'Vietnamese Dong', 'woocommerce' ) ),
|
||||
array( 'code' => 'VUV', 'symbol' => 'VUV', 'name' => __( 'Vanuatu vatu', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'WST', 'symbol' => 'WST', 'name' => __( 'Samoan tala', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XAF', 'symbol' => 'XAF', 'name' => __( 'Central African CFA franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XCD', 'symbol' => 'XCD', 'name' => __( 'East Caribbean dollar', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XDR', 'symbol' => 'XDR', 'name' => __( 'Special Drawing Rights', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XOF', 'symbol' => 'XOF', 'name' => __( 'West African CFA franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XPF', 'symbol' => 'XPF', 'name' => __( 'CFP franc', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ZAR', 'symbol' => 'R', 'name' => __( 'South African rand', 'woocommerce' ) ),
|
||||
array( 'code' => 'ZMK', 'symbol' => 'ZMK', 'name' => __( 'Zambian kwacha', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ZWD', 'symbol' => 'ZWD', 'name' => __( 'Zimbabwean dollar', 'woocommerce-jetpack' ) ),
|
||||
|
||||
array( 'code' => 'AUR', 'symbol' => 'AUR', 'name' => __( 'Auroracoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BCC', 'symbol' => 'BCC', 'name' => __( 'BitConnect', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BCH', 'symbol' => 'BCH', 'name' => __( 'Bitcoin Cash', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'BTC', 'symbol' => 'BTC', 'name' => __( 'Bitcoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'KOI', 'symbol' => 'KOI', 'name' => __( 'Coinye', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XDN', 'symbol' => 'XDN', 'name' => __( 'DigitalNote', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'EMC', 'symbol' => 'EMC', 'name' => __( 'Emercoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ETC', 'symbol' => 'ETC', 'name' => __( 'Ethereum Classic', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ETH', 'symbol' => 'ETH', 'name' => __( 'Ethereum', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'FMC', 'symbol' => 'FMC', 'name' => __( 'Freemasoncoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'GRC', 'symbol' => 'GRC', 'name' => __( 'Gridcoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'IOT', 'symbol' => 'IOT', 'name' => __( 'IOTA', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'LTC', 'symbol' => 'LTC', 'name' => __( 'Litecoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MZC', 'symbol' => 'MZC', 'name' => __( 'MazaCoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XMR', 'symbol' => 'XMR', 'name' => __( 'Monero', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'NMC', 'symbol' => 'NMC', 'name' => __( 'Namecoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XEM', 'symbol' => 'XEM', 'name' => __( 'NEM', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'NXT', 'symbol' => 'NXT', 'name' => __( 'Nxt', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'MSC', 'symbol' => 'MSC', 'name' => __( 'Omni', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'PPC', 'symbol' => 'PPC', 'name' => __( 'Peercoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'POT', 'symbol' => 'POT', 'name' => __( 'PotCoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XPM', 'symbol' => 'XPM', 'name' => __( 'Primecoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'XRP', 'symbol' => 'XRP', 'name' => __( 'Ripple', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'SIL', 'symbol' => 'SIL', 'name' => __( 'SixEleven', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'AMP', 'symbol' => 'AMP', 'name' => __( 'Synereo AMP', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'TIT', 'symbol' => 'TIT', 'name' => __( 'Titcoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'UBQ', 'symbol' => 'UBQ', 'name' => __( 'Ubiq', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'VTC', 'symbol' => 'VTC', 'name' => __( 'Vertcoin', 'woocommerce-jetpack' ) ),
|
||||
array( 'code' => 'ZEC', 'symbol' => 'ZEC', 'name' => __( 'Zcash', 'woocommerce-jetpack' ) ),
|
||||
|
||||
array( 'code' => 'MYC', 'symbol' => 'MYC', 'name' => __( 'myCred', 'woocommerce-jetpack' ) ),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Date and Time
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_check_single_date' ) ) {
|
||||
/**
|
||||
* wcj_check_single_date.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_check_single_date( $_date, $args ) {
|
||||
$_date = explode( '-', $_date );
|
||||
if ( isset( $_date[0] ) ) {
|
||||
if ( $args['day_now'] < $_date[0] ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $_date[1] ) ) {
|
||||
if ( $args['day_now'] > $_date[1] ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_date' ) ) {
|
||||
/**
|
||||
* wcj_check_date.
|
||||
*
|
||||
* @version 2.9.1
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_check_date( $_date, $args = array() ) {
|
||||
if ( empty( $args ) ) {
|
||||
$time_now = current_time( 'timestamp' );
|
||||
$args['day_now'] = intval( date( 'j', $time_now ) );
|
||||
}
|
||||
$_date = explode( ',', $_date );
|
||||
foreach ( $_date as $_single_date ) {
|
||||
if ( wcj_check_single_date( $_single_date, $args ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_time_from' ) ) {
|
||||
/**
|
||||
* wcj_check_time_from.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_check_time_from( $time_from, $args ) {
|
||||
$time_from = explode( ':', $time_from );
|
||||
if ( isset( $time_from[0] ) && $args['hours_now'] < $time_from[0] ) {
|
||||
return false;
|
||||
}
|
||||
if ( isset( $time_from[1] ) && $time_from[0] == $args['hours_now'] && $args['minutes_now'] < $time_from[1] ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_time_to' ) ) {
|
||||
/**
|
||||
* wcj_check_time_to.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_check_time_to( $time_to, $args ) {
|
||||
$time_to = explode( ':', $time_to );
|
||||
if ( isset( $time_to[0] ) && $args['hours_now'] > $time_to[0] ) {
|
||||
return false;
|
||||
}
|
||||
if ( isset( $time_to[1] ) && $time_to[0] == $args['hours_now'] && $args['minutes_now'] > $time_to[1] ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_single_time' ) ) {
|
||||
/**
|
||||
* wcj_check_single_time.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_check_single_time( $_time, $args ) {
|
||||
$_time = explode( '-', $_time );
|
||||
if ( isset( $_time[0] ) ) {
|
||||
if ( ! wcj_check_time_from( $_time[0], $args ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $_time[1] ) ) {
|
||||
if ( ! wcj_check_time_to( $_time[1], $args ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_time' ) ) {
|
||||
/**
|
||||
* wcj_check_time.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_check_time( $_time, $args = array() ) {
|
||||
if ( empty( $args ) ) {
|
||||
$time_now = current_time( 'timestamp' );
|
||||
$args['hours_now'] = intval( date( 'H', $time_now ) );
|
||||
$args['minutes_now'] = intval( date( 'i', $time_now ) );
|
||||
}
|
||||
$_time = explode( ',', $_time );
|
||||
foreach ( $_time as $_single_time ) {
|
||||
if ( wcj_check_single_time( $_single_time, $args ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_date_format_php_to_js' ) ) {
|
||||
/*
|
||||
* Matches each symbol of PHP date format standard
|
||||
* with jQuery equivalent codeword
|
||||
* http://stackoverflow.com/questions/16702398/convert-a-php-date-format-to-a-jqueryui-datepicker-date-format
|
||||
*
|
||||
* @author Tristan Jahier
|
||||
* @version 2.4.0
|
||||
* @since 2.4.0
|
||||
*/
|
||||
function wcj_date_format_php_to_js( $php_format ) {
|
||||
$SYMBOLS_MATCHING = array(
|
||||
// Day
|
||||
'd' => 'dd',
|
||||
'D' => 'D',
|
||||
'j' => 'd',
|
||||
'l' => 'DD',
|
||||
'N' => '',
|
||||
'S' => '',
|
||||
'w' => '',
|
||||
'z' => 'o',
|
||||
// Week
|
||||
'W' => '',
|
||||
// Month
|
||||
'F' => 'MM',
|
||||
'm' => 'mm',
|
||||
'M' => 'M',
|
||||
'n' => 'm',
|
||||
't' => '',
|
||||
// Year
|
||||
'L' => '',
|
||||
'o' => '',
|
||||
'Y' => 'yy',
|
||||
'y' => 'y',
|
||||
// Time
|
||||
'a' => '',
|
||||
'A' => '',
|
||||
'B' => '',
|
||||
'g' => '',
|
||||
'G' => '',
|
||||
'h' => '',
|
||||
'H' => '',
|
||||
'i' => '',
|
||||
's' => '',
|
||||
'u' => ''
|
||||
);
|
||||
$jqueryui_format = "";
|
||||
$escaping = false;
|
||||
for ( $i = 0; $i < strlen( $php_format ); $i++ ) {
|
||||
$char = $php_format[ $i ];
|
||||
if ( $char === '\\' ) { // PHP date format escaping character
|
||||
$i++;
|
||||
$jqueryui_format .= ( $escaping ) ? $php_format[ $i ] : '\'' . $php_format[ $i ];
|
||||
$escaping = true;
|
||||
} else {
|
||||
if ( $escaping ) {
|
||||
$jqueryui_format .= "'";
|
||||
$escaping = false;
|
||||
}
|
||||
$jqueryui_format .= ( isset( $SYMBOLS_MATCHING[ $char ] ) ) ? $SYMBOLS_MATCHING[ $char ] : $char;
|
||||
}
|
||||
}
|
||||
return $jqueryui_format;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Debug
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_log' ) ) {
|
||||
/**
|
||||
* wcj_log.
|
||||
*
|
||||
* @version 3.5.0
|
||||
*/
|
||||
function wcj_log( $message = '', $do_var_dump = false ) {
|
||||
if ( ! wcj_is_module_enabled( 'admin_tools' ) || ( 'no' === get_option( 'wcj_logging_enabled', 'no' ) && 'no' === get_option( 'wcj_wc_logging_enabled', 'no' ) ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $do_var_dump ) {
|
||||
ob_start();
|
||||
var_dump( $message );
|
||||
$message = ob_get_clean();
|
||||
} elseif ( is_array( $message ) || is_object( $message ) ) {
|
||||
$message = print_r( $message, true );
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_logging_enabled', 'no' ) ) {
|
||||
update_option( 'wcj_log', date( 'Y-m-d H:i:s' ) . ' ' . esc_url( $_SERVER['REQUEST_URI'] ) . ' [' . $message . ']' . '<br>' . get_option( 'wcj_log', '' ) );
|
||||
}
|
||||
// WC log
|
||||
if ( 'yes' === get_option( 'wcj_wc_logging_enabled', 'no' ) && function_exists( 'wc_get_logger' ) ) {
|
||||
if ( $log = wc_get_logger() ) {
|
||||
$log->log( 'info', $message, array( 'source' => 'booster_for_woocommerce' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - EU VAT
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_validate_vat_no_soap' ) ) {
|
||||
/**
|
||||
* wcj_validate_vat_no_soap.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.5.7
|
||||
* @return mixed: bool on successful checking (can be true or false), null otherwise
|
||||
*/
|
||||
function wcj_validate_vat_no_soap( $country_code, $vat_number, $method ) {
|
||||
$country_code = strtoupper( $country_code );
|
||||
$api_url = "http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=" . $country_code . "&vat=" . $vat_number;
|
||||
switch ( $method ) {
|
||||
case 'file_get_contents':
|
||||
if ( ini_get( 'allow_url_fopen' ) ) {
|
||||
$response = file_get_contents( $api_url );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
default: // 'curl'
|
||||
if ( function_exists( 'curl_version' ) ) {
|
||||
$curl = curl_init( $api_url );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
|
||||
$response = curl_exec( $curl );
|
||||
curl_close( $curl );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ( false === $response ) {
|
||||
return null;
|
||||
}
|
||||
return ( false !== strpos( $response, '="validStyle"' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_validate_vat_soap' ) ) {
|
||||
/**
|
||||
* wcj_validate_vat_soap.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @return mixed: bool on successful checking (can be true or false), null otherwise
|
||||
*/
|
||||
function wcj_validate_vat_soap( $country_code, $vat_number ) {
|
||||
try {
|
||||
if ( class_exists( 'SoapClient' ) ) {
|
||||
$client = new SoapClient(
|
||||
'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl',
|
||||
array( 'exceptions' => true )
|
||||
);
|
||||
$result = $client->checkVat( array(
|
||||
'countryCode' => $country_code,
|
||||
'vatNumber' => $vat_number,
|
||||
) );
|
||||
return ( isset( $result->valid ) ) ? $result->valid : null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch( Exception $exception ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_validate_vat_with_method' ) ) {
|
||||
/**
|
||||
* wcj_validate_vat_with_method.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @return mixed: bool on successful checking (can be true or false), null otherwise
|
||||
*/
|
||||
function wcj_validate_vat_with_method( $country_code, $vat_number, $method ) {
|
||||
switch ( $method ) {
|
||||
case 'soap':
|
||||
return wcj_validate_vat_soap( $country_code, $vat_number );
|
||||
default: // 'curl', 'file_get_contents'
|
||||
return wcj_validate_vat_no_soap( $country_code, $vat_number, $method );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_validate_vat' ) ) {
|
||||
/**
|
||||
* wcj_validate_vat.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 2.9.0
|
||||
* @return mixed: bool on successful checking (can be true or false), null otherwise
|
||||
*/
|
||||
function wcj_validate_vat( $country_code, $vat_number ) {
|
||||
if ( '' != ( $skip_countries = get_option( 'wcj_eu_vat_number_advanced_skip_countries', array() ) ) ) {
|
||||
$skip_countries = array_map( 'trim', explode( ',', $skip_countries ) );
|
||||
$skip_countries = array_map( 'strtoupper', $skip_countries );
|
||||
if ( in_array( strtoupper( $country_code ), $skip_countries ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$methods = array();
|
||||
switch ( get_option( 'wcj_eu_vat_number_first_method', 'soap' ) ) {
|
||||
case 'curl':
|
||||
$methods = array( 'curl', 'file_get_contents', 'soap' );
|
||||
break;
|
||||
case 'file_get_contents':
|
||||
$methods = array( 'file_get_contents', 'curl', 'soap' );
|
||||
break;
|
||||
default: // 'soap'
|
||||
$methods = array( 'soap', 'curl', 'file_get_contents' );
|
||||
break;
|
||||
}
|
||||
foreach ( $methods as $method ) {
|
||||
if ( null !== ( $result = wcj_validate_vat_with_method( $country_code, $vat_number, $method ) ) ) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Exchange Rates
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_saved_exchange_rate' ) ) {
|
||||
/**
|
||||
* wcj_get_saved_exchange_rate.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 3.2.4
|
||||
* @todo (maybe) need to check if `currency_exchange_rates` module `is_enabled()`
|
||||
*/
|
||||
function wcj_get_saved_exchange_rate( $from, $to ) {
|
||||
if ( $from == $to ) {
|
||||
return 1;
|
||||
}
|
||||
// Preparing `active_currencies` array
|
||||
if ( ! isset( WCJ()->modules['currency_exchange_rates']->active_currencies ) ) {
|
||||
$active_currencies_settings = WCJ()->modules['currency_exchange_rates']->get_all_currencies_exchange_rates_settings();
|
||||
$active_currencies = array();
|
||||
foreach ( $active_currencies_settings as $currency ) {
|
||||
$active_currencies[ str_replace( 'wcj_currency_exchange_rates_', '', $currency['id'] ) ] = get_option( $currency['id'] );
|
||||
}
|
||||
WCJ()->modules['currency_exchange_rates']->active_currencies = $active_currencies;
|
||||
} else {
|
||||
$active_currencies = WCJ()->modules['currency_exchange_rates']->active_currencies;
|
||||
}
|
||||
if ( empty( $active_currencies ) ) {
|
||||
return 0;
|
||||
}
|
||||
// Getting exchange rate - simple method
|
||||
$exchange_rate = ( isset( $active_currencies[ sanitize_title( $from . $to ) ] ) ? $active_currencies[ sanitize_title( $from . $to ) ] : 0 );
|
||||
// Getting exchange rate - invert method
|
||||
if ( 0 == $exchange_rate ) {
|
||||
$exchange_rate = ( isset( $active_currencies[ sanitize_title( $to . $from ) ] ) ? $active_currencies[ sanitize_title( $to . $from ) ] : 0 );
|
||||
if ( 0 != $exchange_rate ) {
|
||||
$exchange_rate = 1 / $exchange_rate;
|
||||
}
|
||||
}
|
||||
// Getting exchange rate - shop base
|
||||
if ( 0 == $exchange_rate ) {
|
||||
$shop_currency = get_option( 'woocommerce_currency' );
|
||||
$exchange_rate_from = ( isset( $active_currencies[ sanitize_title( $shop_currency . $from ) ] ) ? $active_currencies[ sanitize_title( $shop_currency . $from ) ] : 0 );
|
||||
$exchange_rate_to = ( isset( $active_currencies[ sanitize_title( $shop_currency . $to ) ] ) ? $active_currencies[ sanitize_title( $shop_currency . $to ) ] : 0 );
|
||||
if ( 0 != $exchange_rate_from ) {
|
||||
$exchange_rate = $exchange_rate_to / $exchange_rate_from;
|
||||
}
|
||||
}
|
||||
return $exchange_rate;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rate_servers' ) ) {
|
||||
/**
|
||||
* wcj_get_currency_exchange_rate_servers.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_get_currency_exchange_rate_servers() {
|
||||
return apply_filters( 'wcj_currency_exchange_rates_servers', array(
|
||||
'yahoo' => __( 'Yahoo', 'woocommerce-jetpack' ),
|
||||
'ecb' => __( 'European Central Bank (ECB)', 'woocommerce-jetpack' ) . ' [' . __( 'recommended', 'woocommerce-jetpack' ) . ']',
|
||||
'tcmb' => __( 'TCMB', 'woocommerce-jetpack' ),
|
||||
'fixer' => __( 'Fixer.io', 'woocommerce-jetpack' ),
|
||||
'coinbase' => __( 'Coinbase', 'woocommerce-jetpack' ),
|
||||
'coinmarketcap' => __( 'CoinMarketCap', 'woocommerce-jetpack' ),
|
||||
'google' => __( 'Google', 'woocommerce-jetpack' ),
|
||||
'boe' => __( 'Bank of England (BOE)', 'woocommerce-jetpack' ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rate_server' ) ) {
|
||||
/*
|
||||
* wcj_get_currency_exchange_rate_server.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_get_currency_exchange_rate_server( $currency_from, $currency_to ) {
|
||||
if ( 'default_server' === ( $server = get_option( 'wcj_currency_exchange_rates_server_' . sanitize_title( $currency_from . $currency_to ), 'default_server' ) ) ) {
|
||||
return get_option( 'wcj_currency_exchange_rates_server', 'ecb' );
|
||||
}
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rate_offset_percent' ) ) {
|
||||
/*
|
||||
* wcj_get_currency_exchange_rate_offset_percent.
|
||||
*
|
||||
* @version 3.4.5
|
||||
* @since 3.4.5
|
||||
*/
|
||||
function wcj_get_currency_exchange_rate_offset_percent( $currency_from, $currency_to ) {
|
||||
$field_id = 'wcj_currency_exchange_rates_offset_percent_' . sanitize_title( $currency_from . $currency_to );
|
||||
if ( 'default_offset' === get_option( $field_id, 'default_offset' ) ) {
|
||||
return get_option( 'wcj_currency_exchange_rates_offset_percent', 0 );
|
||||
}
|
||||
return get_option( $field_id . '_' . 'custom_offset', 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rate_server_name' ) ) {
|
||||
/*
|
||||
* wcj_get_currency_exchange_rate_server_name.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_get_currency_exchange_rate_server_name( $currency_from, $currency_to ) {
|
||||
$servers = wcj_get_currency_exchange_rate_servers();
|
||||
$server = wcj_get_currency_exchange_rate_server( $currency_from, $currency_to );
|
||||
return ( isset( $servers[ $server ] ) ? $servers[ $server ] : $server );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_get_exchange_rate.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
$exchange_rates_server = wcj_get_currency_exchange_rate_server( $currency_from, $currency_to );
|
||||
if ( 'yes' === ( $calculate_by_invert = get_option( 'wcj_currency_exchange_rates_calculate_by_invert', 'no' ) ) ) {
|
||||
$_currency_to = $currency_to;
|
||||
$currency_to = $currency_from;
|
||||
$currency_from = $_currency_to;
|
||||
}
|
||||
switch ( $exchange_rates_server ) {
|
||||
case 'tcmb':
|
||||
$return = wcj_tcmb_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'yahoo':
|
||||
$return = wcj_yahoo_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'fixer':
|
||||
$return = wcj_fixer_io_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'coinbase':
|
||||
$return = wcj_coinbase_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'coinmarketcap':
|
||||
$return = wcj_coinmarketcap_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'google':
|
||||
$return = wcj_google_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'boe':
|
||||
$return = wcj_boe_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
case 'ecb':
|
||||
$return = wcj_ecb_get_exchange_rate( $currency_from, $currency_to );
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
$return = apply_filters( 'wcj_currency_exchange_rate', $return, $exchange_rates_server, $currency_from, $currency_to );
|
||||
return ( 'yes' === $calculate_by_invert ) ? round( ( 1 / $return ), 6 ) : $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rates_url_response' ) ) {
|
||||
/*
|
||||
* wcj_get_currency_exchange_rates_url_response.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.2.4
|
||||
* @todo use where needed
|
||||
*/
|
||||
function wcj_get_currency_exchange_rates_url_response( $url, $do_json_decode = true ) {
|
||||
$response = '';
|
||||
if ( 'no' === get_option( 'wcj_currency_exchange_rates_always_curl', 'no' ) && ini_get( 'allow_url_fopen' ) ) {
|
||||
$response = file_get_contents( $url );
|
||||
} elseif ( function_exists( 'curl_version' ) ) {
|
||||
$curl = curl_init( $url );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
|
||||
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
|
||||
$response = curl_exec( $curl );
|
||||
curl_close( $curl );
|
||||
}
|
||||
return ( '' != $response ? ( $do_json_decode ? json_decode( $response ) : $response ) : false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_boe_get_exchange_rate_gbp' ) ) {
|
||||
/*
|
||||
* wcj_boe_get_exchange_rate_gbp.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_boe_get_exchange_rate_gbp( $currency_to ) {
|
||||
if ( 'GBP' == $currency_to ) {
|
||||
return 1;
|
||||
}
|
||||
$final_rate = false;
|
||||
$currency_codes = array(
|
||||
'AUD' => 'EC3', // Australian Dollar
|
||||
'CAD' => 'ECL', // Canadian Dollar
|
||||
'CNY' => 'INB', // Chinese Yuan
|
||||
'CZK' => 'DS7', // Czech Koruna
|
||||
'DKK' => 'ECH', // Danish Krone
|
||||
'EUR' => 'C8J', // Euro
|
||||
'HKD' => 'ECN', // Hong Kong Dollar
|
||||
'HUF' => '5LA', // Hungarian Forint
|
||||
'INR' => 'INE', // Indian Rupee
|
||||
'ILS' => 'IN7', // Israeli Shekel
|
||||
'JPY' => 'C8N', // Japanese Yen
|
||||
'MYR' => 'IN8', // Malaysian ringgit
|
||||
'NZD' => 'ECO', // New Zealand Dollar
|
||||
'NOK' => 'EC6', // Norwegian Krone
|
||||
'PLN' => '5OW', // Polish Zloty
|
||||
'RUB' => 'IN9', // Russian Ruble
|
||||
'SAR' => 'ECZ', // Saudi Riyal
|
||||
'SGD' => 'ECQ', // Singapore Dollar
|
||||
'ZAR' => 'ECE', // South African Rand
|
||||
'KRW' => 'INC', // South Korean Won
|
||||
'SEK' => 'ECC', // Swedish Krona
|
||||
'CHF' => 'ECU', // Swiss Franc
|
||||
'TWD' => 'ECD', // Taiwan Dollar
|
||||
'THB' => 'INA', // Thai Baht
|
||||
'TRY' => 'IND', // Turkish Lira
|
||||
'USD' => 'C8P', // US Dollar
|
||||
);
|
||||
if ( isset( $currency_codes[ $currency_to ] ) && function_exists( 'simplexml_load_file' ) ) {
|
||||
for ( $i = 1; $i <= 7; $i++ ) {
|
||||
$date = time() - $i*24*60*60;
|
||||
$date_from_d = date( 'd', $date );
|
||||
$date_from_m = date( 'M', $date );
|
||||
$date_from_y = date( 'Y', $date );
|
||||
$date_to_d = date( 'd', $date );
|
||||
$date_to_m = date( 'M', $date );
|
||||
$date_to_y = date( 'Y', $date );
|
||||
$date_url = '&FD=' . $date_from_d . '&FM=' . $date_from_m . '&FY=' . $date_from_y . '&TD=' . $date_to_d . '&TM=' . $date_to_m . '&TY=' . $date_to_y;
|
||||
$url = 'http://www.bankofengland.co.uk/boeapps/iadb/fromshowcolumns.asp?Travel=NIxRSxSUx&FromSeries=1&ToSeries=50&DAT=RNG' . $date_url .
|
||||
'&VFD=Y&xml.x=23&xml.y=18&CSVF=TT&C=' . $currency_codes[ $currency_to ] . '&Filter=N';
|
||||
$xml = simplexml_load_file( $url );
|
||||
$json_string = json_encode( $xml );
|
||||
$result_array = json_decode( $json_string, true );
|
||||
if ( isset( $result_array['Cube']['Cube'] ) ) {
|
||||
$last_element_index = count( $result_array['Cube']['Cube'] ) - 1;
|
||||
if ( isset( $result_array['Cube']['Cube'][ $last_element_index ]['@attributes']['OBS_VALUE'] ) ) {
|
||||
return $result_array['Cube']['Cube'][ $last_element_index ]['@attributes']['OBS_VALUE'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $final_rate;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_boe_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_boe_get_exchange_rate.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_boe_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
if (
|
||||
false != ( $gbp_currency_from = wcj_boe_get_exchange_rate_gbp( $currency_from ) ) &&
|
||||
false != ( $gbp_currency_to = wcj_boe_get_exchange_rate_gbp( $currency_to ) )
|
||||
) {
|
||||
return round( $gbp_currency_to / $gbp_currency_from, 6 );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_google_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_google_get_exchange_rate.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @see https://gist.github.com/daveismyname/8067095
|
||||
*/
|
||||
function wcj_google_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
$amount = 1;
|
||||
$url = 'https://finance.google.com/finance/converter?a=' . $amount . '&from=' . $currency_from . '&to=' . $currency_to;
|
||||
if ( false != ( $response = wcj_get_currency_exchange_rates_url_response( $url, false ) ) ) {
|
||||
preg_match( "/<span class=bld>(.*)<\/span>/", $response, $converted );
|
||||
if ( isset( $converted[1] ) ) {
|
||||
if ( $converted = preg_replace( "/[^0-9.]/", "", $converted[1] ) ) {
|
||||
if ( $return = round( $converted, 6 ) ) {
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_coinmarketcap_get_exchange_rate_specific' ) ) {
|
||||
/*
|
||||
* wcj_coinmarketcap_get_exchange_rate_specific.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
* @see https://coinmarketcap.com/api/
|
||||
* @todo add more `$cryptocurrencies_ids`
|
||||
* @todo (maybe) try reverse only if `! isset( $cryptocurrencies_ids[ $currency_from ] )`
|
||||
*/
|
||||
function wcj_coinmarketcap_get_exchange_rate_specific( $currency_from, $currency_to, $try_reverse = true ) {
|
||||
$return = false;
|
||||
$cryptocurrencies_ids = array(
|
||||
'BTC' => 'bitcoin',
|
||||
'XRP' => 'ripple',
|
||||
);
|
||||
if ( isset( $cryptocurrencies_ids[ $currency_from ] ) ) {
|
||||
$url = 'https://api.coinmarketcap.com/v1/ticker/' . $cryptocurrencies_ids[ $currency_from ] . '/?convert=' . $currency_to;
|
||||
if ( false != ( $response = wcj_get_currency_exchange_rates_url_response( $url ) ) ) {
|
||||
$att = 'price_' . strtolower( $currency_to );
|
||||
$return = ( isset( $response[0]->{$att} ) ? $response[0]->{$att} : false );
|
||||
}
|
||||
}
|
||||
if ( false === $return && $try_reverse ) {
|
||||
$return = wcj_coinmarketcap_get_exchange_rate_specific( $currency_to, $currency_from, false );
|
||||
if ( 0 != $return ) {
|
||||
$return = round( ( 1 / $return ), 12 );
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_coinmarketcap_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_coinmarketcap_get_exchange_rate.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
* @see https://coinmarketcap.com/api/
|
||||
* @todo `WCJ()->modules['currency_exchange_rates']->coinmarketcap_response`
|
||||
* @todo `wcj_coinmarketcap_get_exchange_rate_specific()`
|
||||
* @todo (maybe) `limit=0`
|
||||
*/
|
||||
function wcj_coinmarketcap_get_exchange_rate( $currency_from, $currency_to, $try_reverse = true ) {
|
||||
$return = false;
|
||||
/*
|
||||
if ( ! isset( WCJ()->modules['currency_exchange_rates']->coinmarketcap_response ) ) {
|
||||
$response = wcj_get_currency_exchange_rates_url_response( 'https://api.coinmarketcap.com/v1/ticker/?convert=' . $currency_to );
|
||||
if ( false != $response ) {
|
||||
WCJ()->modules['currency_exchange_rates']->coinmarketcap_response = $response;
|
||||
}
|
||||
} else {
|
||||
$response = WCJ()->modules['currency_exchange_rates']->coinmarketcap_response;
|
||||
}
|
||||
*/
|
||||
if ( false != ( $response = wcj_get_currency_exchange_rates_url_response( 'https://api.coinmarketcap.com/v1/ticker/?convert=' . $currency_to ) ) && is_array( $response ) ) {
|
||||
foreach ( $response as $pair ) {
|
||||
if ( isset( $pair->symbol ) && $currency_from === $pair->symbol ) {
|
||||
$att = 'price_' . strtolower( $currency_to );
|
||||
$return = ( isset( $pair->{$att} ) ? $pair->{$att} : false );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( false === $return && $try_reverse ) {
|
||||
$return = wcj_coinmarketcap_get_exchange_rate( $currency_to, $currency_from, false );
|
||||
if ( 0 != $return ) {
|
||||
$return = round( ( 1 / $return ), 12 );
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_coinbase_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_coinbase_get_exchange_rate.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.4
|
||||
*/
|
||||
function wcj_coinbase_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
$response = wcj_get_currency_exchange_rates_url_response( "https://api.coinbase.com/v2/exchange-rates?currency=$currency_from" );
|
||||
return ( isset( $response->data->rates->{$currency_to} ) ? $response->data->rates->{$currency_to} : false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_ecb_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_ecb_get_exchange_rate.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_ecb_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
$final_rate = false;
|
||||
if ( function_exists( 'simplexml_load_file' ) ) {
|
||||
$xml = simplexml_load_file( 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml' );
|
||||
if ( isset( $xml->Cube->Cube->Cube ) ) {
|
||||
if ( 'EUR' === $currency_from ) {
|
||||
$EUR_currency_from_rate = 1;
|
||||
}
|
||||
if ( 'EUR' === $currency_to ) {
|
||||
$EUR_currency_to_rate = 1;
|
||||
}
|
||||
foreach ( $xml->Cube->Cube->Cube as $currency_rate ) {
|
||||
$currency_rate = $currency_rate->attributes();
|
||||
if ( ! isset( $EUR_currency_from_rate ) && $currency_from == $currency_rate->currency ) {
|
||||
$EUR_currency_from_rate = (float) $currency_rate->rate;
|
||||
}
|
||||
if ( ! isset( $EUR_currency_to_rate ) && $currency_to == $currency_rate->currency ) {
|
||||
$EUR_currency_to_rate = (float) $currency_rate->rate;
|
||||
}
|
||||
}
|
||||
if ( isset( $EUR_currency_from_rate ) && isset( $EUR_currency_to_rate ) && 0 != $EUR_currency_from_rate ) {
|
||||
$final_rate = round( $EUR_currency_to_rate / $EUR_currency_from_rate, 6 );
|
||||
} else {
|
||||
$final_rate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $final_rate;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_tcmb_get_exchange_rate_TRY' ) ) {
|
||||
/*
|
||||
* wcj_tcmb_get_exchange_rate_TRY.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_tcmb_get_exchange_rate_TRY( $currency_from ) {
|
||||
if ( 'TRY' === $currency_from ) {
|
||||
return 1;
|
||||
}
|
||||
$xml = simplexml_load_file( 'http://www.tcmb.gov.tr/kurlar/today.xml' );
|
||||
if ( isset( $xml->Currency ) ) {
|
||||
foreach ( $xml->Currency as $the_rate ) {
|
||||
$attributes = $the_rate->attributes();
|
||||
if ( isset( $attributes['CurrencyCode'] ) ) {
|
||||
$currency_code = (string) $attributes['CurrencyCode'];
|
||||
if ( $currency_code === $currency_from ) {
|
||||
// Possible values: ForexSelling, ForexBuying, BanknoteSelling, BanknoteBuying. Not used: CrossRateUSD, CrossRateOther.
|
||||
if ( '' != ( $property_to_check = apply_filters( 'wcj_currency_exchange_rates_tcmb_property_to_check', '' ) ) ) {
|
||||
if ( isset( $the_rate->{$property_to_check} ) ) {
|
||||
$rate = (float) $the_rate->{$property_to_check};
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ( isset( $the_rate->ForexSelling ) ) {
|
||||
$rate = (float) $the_rate->ForexSelling;
|
||||
} elseif ( isset( $the_rate->ForexBuying ) ) {
|
||||
$rate = (float) $the_rate->ForexBuying;
|
||||
} elseif ( isset( $the_rate->BanknoteSelling ) ) {
|
||||
$rate = (float) $the_rate->BanknoteSelling;
|
||||
} elseif ( isset( $the_rate->BanknoteBuying ) ) {
|
||||
$rate = (float) $the_rate->BanknoteBuying;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$unit = ( isset( $the_rate->Unit ) ) ? (float) $the_rate->Unit : 1;
|
||||
return ( $rate / $unit );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_tcmb_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_tcmb_get_exchange_rate.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function wcj_tcmb_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
$currency_from_TRY = wcj_tcmb_get_exchange_rate_TRY( strtoupper( $currency_from ) );
|
||||
if ( false == $currency_from_TRY ) {
|
||||
return false;
|
||||
}
|
||||
$currency_to_TRY = wcj_tcmb_get_exchange_rate_TRY( strtoupper( $currency_to ) );
|
||||
if ( false == $currency_to_TRY ) {
|
||||
return false;
|
||||
}
|
||||
if ( 1 == $currency_to_TRY ) {
|
||||
return round( $currency_from_TRY, 6 );
|
||||
}
|
||||
return round( ( $currency_from_TRY / $currency_to_TRY ), 6 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_yahoo_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_yahoo_get_exchange_rate.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @return float rate on success, else 0
|
||||
*/
|
||||
function wcj_yahoo_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
$response = wcj_get_currency_exchange_rates_url_response( "https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json" );
|
||||
if ( ! isset( $response->list->resources ) ) {
|
||||
return false;
|
||||
}
|
||||
$currencies = array(
|
||||
'currency_from' => array(
|
||||
'name' => $currency_from . '=X',
|
||||
'usd_rate' => false,
|
||||
),
|
||||
'currency_to' => array(
|
||||
'name' => $currency_to . '=X',
|
||||
'usd_rate' => false,
|
||||
),
|
||||
);
|
||||
foreach ( $currencies as &$currency ) {
|
||||
foreach ( $response->list->resources as $resource ) {
|
||||
if ( isset( $resource->resource->fields->symbol ) && $currency['name'] === $resource->resource->fields->symbol ) {
|
||||
if ( ! isset( $resource->resource->fields->price ) ) {
|
||||
return false;
|
||||
}
|
||||
$currency['usd_rate'] = $resource->resource->fields->price;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ( false == $currencies['currency_to']['usd_rate'] || false == $currencies['currency_from']['usd_rate'] ? false :
|
||||
round( ( $currencies['currency_to']['usd_rate'] / $currencies['currency_from']['usd_rate'] ), 6 ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_fixer_io_get_exchange_rate' ) ) {
|
||||
/*
|
||||
* wcj_fixer_io_get_exchange_rate.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 3.2.2
|
||||
* @return false or rate
|
||||
*/
|
||||
function wcj_fixer_io_get_exchange_rate( $currency_from, $currency_to ) {
|
||||
return wcj_fixer_io_get_exchange_rate_by_date( $currency_from, $currency_to, 'latest' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_fixer_io_get_exchange_rate_by_date' ) ) {
|
||||
/*
|
||||
* wcj_fixer_io_get_exchange_rate_by_date.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 3.2.2
|
||||
* @return false or rate
|
||||
*/
|
||||
function wcj_fixer_io_get_exchange_rate_by_date( $currency_from, $currency_to, $date ) {
|
||||
$response = wcj_get_currency_exchange_rates_url_response( 'https://api.fixer.io/' . $date . '?base=' . $currency_from . '&symbols=' . $currency_to );
|
||||
return ( isset( $response->rates->{$currency_to} ) ? $response->rates->{$currency_to} : false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_fixer_io_get_exchange_rate_average' ) ) {
|
||||
/*
|
||||
* wcj_fixer_io_get_exchange_rate_average.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 3.2.2
|
||||
* @return false or rate
|
||||
* @todo customizable '+1 day' (could be '+1 week' etc.)
|
||||
*/
|
||||
function wcj_fixer_io_get_exchange_rate_average( $currency_from, $currency_to, $start_date, $end_date ) {
|
||||
$average_rate = 0;
|
||||
$average_rate_counter = 0;
|
||||
$start_date = new DateTime( $start_date );
|
||||
$end_date = new DateTime( $end_date );
|
||||
for ( $i = $start_date; $i <= $end_date; $i->modify( '+1 day' ) ) {
|
||||
$date = $i->format( "Y-m-d" );
|
||||
$rate = wcj_fixer_io_get_exchange_rate_by_date( $currency_from, $currency_to, $date );
|
||||
if ( false != $rate ) {
|
||||
$average_rate += $rate;
|
||||
$average_rate_counter++;
|
||||
}
|
||||
}
|
||||
return ( 0 == $average_rate || 0 == $average_rate_counter ? false : round( ( $average_rate / $average_rate_counter ), 6 ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,765 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - General
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
* @todo add `wcj_add_actions()` and `wcj_add_filters()`
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_wpml_default_language' ) ) {
|
||||
/**
|
||||
* wcj_get_wpml_default_language.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 3.7.0
|
||||
*/
|
||||
function wcj_get_wpml_default_language() {
|
||||
global $sitepress;
|
||||
if ( $sitepress ) {
|
||||
return $sitepress->get_default_language();
|
||||
} elseif ( function_exists( 'icl_get_setting' ) ) {
|
||||
return icl_get_setting( 'default_language' );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_array' ) ) {
|
||||
/**
|
||||
* wcj_get_array.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function wcj_get_array( $value ) {
|
||||
return ( ! is_array( $value ) ? array( $value ) : $value );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_product_in_cart' ) ) {
|
||||
/**
|
||||
* wcj_is_product_in_cart.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.9.1
|
||||
*/
|
||||
function wcj_is_product_in_cart( $product_id ) {
|
||||
if ( 0 != $product_id ) {
|
||||
if ( isset( WC()->cart->cart_contents ) && is_array( WC()->cart->cart_contents ) ) {
|
||||
foreach ( WC()->cart->cart_contents as $cart_item_key => $cart_item_data ) {
|
||||
if (
|
||||
( isset( $cart_item_data['product_id'] ) && $product_id == $cart_item_data['product_id'] ) ||
|
||||
( isset( $cart_item_data['variation_id'] ) && $product_id == $cart_item_data['variation_id'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_send_file' ) ) {
|
||||
/**
|
||||
* wcj_send_file.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo use where needed
|
||||
* @todo add more cases for `$file_type`
|
||||
*/
|
||||
function wcj_send_file( $file_name, $file_path, $file_type, $do_clean_up = true ) {
|
||||
switch ( $file_type ) {
|
||||
default: // 'zip'
|
||||
header( "Content-Type: application/octet-stream" );
|
||||
header( "Content-Disposition: attachment; filename=" . urlencode( $file_name ) );
|
||||
header( "Content-Type: application/octet-stream" );
|
||||
header( "Content-Type: application/download" );
|
||||
header( "Content-Description: File Transfer" );
|
||||
header( "Content-Length: " . filesize( $file_path ) );
|
||||
break;
|
||||
}
|
||||
flush(); // this doesn't really matter.
|
||||
if ( false !== ( $fp = fopen( $file_path, "r" ) ) ) {
|
||||
while ( ! feof( $fp ) ) {
|
||||
echo fread( $fp, 65536 );
|
||||
flush(); // this is essential for large downloads
|
||||
}
|
||||
fclose( $fp );
|
||||
if ( $do_clean_up ) {
|
||||
@unlink( $file_path );
|
||||
}
|
||||
exit();
|
||||
} else {
|
||||
die( __( 'Unexpected error', 'woocommerce-jetpack' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_parse_number' ) ) {
|
||||
/**
|
||||
* wcj_parse_number.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo maybe there is a better way (e.g. `numfmt_parse()`)
|
||||
*/
|
||||
function wcj_parse_number( $number_string ) {
|
||||
if ( false !== strpos( $number_string, '.' ) ) {
|
||||
return str_replace( ',', '', $number_string );
|
||||
} else {
|
||||
return str_replace( ',', '.', $number_string );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_handle_replacements' ) ) {
|
||||
/**
|
||||
* wcj_handle_replacements.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function wcj_handle_replacements( $replacements, $template ) {
|
||||
return str_replace( array_keys( $replacements ), $replacements, $template );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_js_confirmation' ) ) {
|
||||
/**
|
||||
* wcj_get_js_confirmation.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.3.0
|
||||
* @todo use where needed
|
||||
*/
|
||||
function wcj_get_js_confirmation( $confirmation_message = '' ) {
|
||||
if ( '' === $confirmation_message ) {
|
||||
$confirmation_message = __( 'Are you sure?', 'woocommerce-jetpack' );
|
||||
}
|
||||
return ' onclick="return confirm(\'' . $confirmation_message . '\')"';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_tcpdf_method' ) ) {
|
||||
/**
|
||||
* wcj_tcpdf_method.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.4.0
|
||||
*/
|
||||
function wcj_tcpdf_method( $method, $params ) {
|
||||
return '<tcpdf method="' . $method . '" wcj_tcpdf_method_params_start' . serialize( $params ) . 'wcj_tcpdf_method_params_end />';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_tcpdf_barcode' ) ) {
|
||||
/**
|
||||
* wcj_tcpdf_barcode.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.3.0
|
||||
* @todo `color`
|
||||
* @todo `align` (try 'T')
|
||||
*/
|
||||
function wcj_tcpdf_barcode( $atts ) {
|
||||
if ( '' === $atts['code'] ) {
|
||||
return '';
|
||||
}
|
||||
if ( '' === $atts['type'] ) {
|
||||
$atts['type'] = ( '1D' === $atts['dimension'] ? 'C39' : 'PDF417' );
|
||||
}
|
||||
if ( 0 === $atts['width'] ) {
|
||||
$atts['width'] = ( '1D' === $atts['dimension'] ? 80 : 80 );
|
||||
}
|
||||
if ( 0 === $atts['height'] ) {
|
||||
$atts['height'] = ( '1D' === $atts['dimension'] ? 30 : 80 );
|
||||
}
|
||||
if ( '1D' === $atts['dimension'] ) {
|
||||
$params = array(
|
||||
$atts['code'],
|
||||
$atts['type'],
|
||||
'', // x
|
||||
'', // y
|
||||
$atts['width'],
|
||||
$atts['height'],
|
||||
0.4, // xres
|
||||
array( // style
|
||||
'position' => 'S',
|
||||
'border' => false,
|
||||
'padding' => 4,
|
||||
'fgcolor' => array( 0, 0, 0 ),
|
||||
'bgcolor' => array( 255, 255, 255 ),
|
||||
'text' => false,
|
||||
),
|
||||
'N', // align
|
||||
);
|
||||
} else {
|
||||
$params = array(
|
||||
$atts['code'],
|
||||
$atts['type'],
|
||||
'', // x
|
||||
'', // y
|
||||
$atts['width'],
|
||||
$atts['height'],
|
||||
array( // style
|
||||
'border' => false,
|
||||
'vpadding' => 'auto',
|
||||
'hpadding' => 'auto',
|
||||
'fgcolor' => array( 0, 0, 0 ),
|
||||
'bgcolor' => array( 255, 255, 255 ),
|
||||
'module_width' => 1, // width of a single module in points
|
||||
'module_height' => 1, // height of a single module in points
|
||||
),
|
||||
'N', // align
|
||||
false, // distort
|
||||
);
|
||||
}
|
||||
return wcj_tcpdf_method( ( '1D' === $atts['dimension'] ? 'write1DBarcode' : 'write2DBarcode' ), $params );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_barcode' ) ) {
|
||||
/**
|
||||
* wcj_barcode.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.3.0
|
||||
* @todo (maybe) "Barcodes" module
|
||||
* @todo (maybe) `getBarcodePNG()`
|
||||
*/
|
||||
function wcj_barcode( $atts ) {
|
||||
if ( '' === $atts['code'] ) {
|
||||
return '';
|
||||
}
|
||||
if ( '' === $atts['type'] ) {
|
||||
$atts['type'] = ( '1D' === $atts['dimension'] ? 'C39' : 'PDF417' );
|
||||
}
|
||||
if ( 0 === $atts['width'] ) {
|
||||
$atts['width'] = ( '1D' === $atts['dimension'] ? 2 : 10 );
|
||||
}
|
||||
if ( 0 === $atts['height'] ) {
|
||||
$atts['height'] = ( '1D' === $atts['dimension'] ? 30 : 10 );
|
||||
}
|
||||
if ( '1D' === $atts['dimension'] ) {
|
||||
require_once( WCJ_PLUGIN_PATH . '/includes/lib/tcpdf/tcpdf_barcodes_1d.php' );
|
||||
$barcode = new TCPDFBarcode( $atts['code'], $atts['type'] );
|
||||
} else {
|
||||
require_once( WCJ_PLUGIN_PATH . '/includes/lib/tcpdf/tcpdf_barcodes_2d.php' );
|
||||
$barcode = new TCPDF2DBarcode( $atts['code'], $atts['type'] );
|
||||
}
|
||||
$barcode_array = $barcode->getBarcodeArray();
|
||||
return ( ! empty( $barcode_array ) && is_array( $barcode_array ) ? $barcode->getBarcodeHTML( $atts['width'], $atts['height'], $atts['color'] ) : '' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_session_maybe_start' ) ) {
|
||||
/**
|
||||
* wcj_session_maybe_start.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_session_maybe_start() {
|
||||
switch ( WCJ_SESSION_TYPE ) {
|
||||
case 'wc':
|
||||
if ( function_exists( 'WC' ) && WC()->session && ! WC()->session->has_session() ) {
|
||||
WC()->session->set_customer_session_cookie( true );
|
||||
}
|
||||
break;
|
||||
default: // 'standard'
|
||||
if ( ! session_id() ) {
|
||||
session_start();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_session_set' ) ) {
|
||||
/**
|
||||
* wcj_session_set.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_session_set( $key, $value ) {
|
||||
switch ( WCJ_SESSION_TYPE ) {
|
||||
case 'wc':
|
||||
if ( function_exists( 'WC' ) && WC()->session ) {
|
||||
WC()->session->set( $key, $value );
|
||||
}
|
||||
break;
|
||||
default: // 'standard'
|
||||
$_SESSION[ $key ] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_session_get' ) ) {
|
||||
/**
|
||||
* wcj_session_get.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_session_get( $key, $default = null ) {
|
||||
switch ( WCJ_SESSION_TYPE ) {
|
||||
case 'wc':
|
||||
return ( function_exists( 'WC' ) && WC()->session ? WC()->session->get( $key, $default ) : $default );
|
||||
default: // 'standard'
|
||||
return ( isset( $_SESSION[ $key ] ) ? $_SESSION[ $key ] : $default );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_wrap_in_wc_email_template' ) ) {
|
||||
/**
|
||||
* wcj_wrap_in_wc_email_template.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_wrap_in_wc_email_template( $content, $email_heading = '' ) {
|
||||
return wcj_get_wc_email_part( 'header', $email_heading ) . $content . wcj_get_wc_email_part( 'footer' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_wc_email_part' ) ) {
|
||||
/**
|
||||
* wcj_get_wc_email_part.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_get_wc_email_part( $part, $email_heading = '' ) {
|
||||
ob_start();
|
||||
switch ( $part ) {
|
||||
case 'header':
|
||||
wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
|
||||
break;
|
||||
case 'footer':
|
||||
wc_get_template( 'emails/email-footer.php' );
|
||||
break;
|
||||
}
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_add_date_query' ) ) {
|
||||
/**
|
||||
* wcj_maybe_add_date_query.
|
||||
*
|
||||
* @version 3.0.0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
function wcj_maybe_add_date_query( $args ) {
|
||||
if ( ( isset( $_GET['start_date'] ) && '' != $_GET['start_date'] ) || ( isset( $_GET['end_date'] ) && '' != $_GET['end_date'] ) ) {
|
||||
$date_query = array();
|
||||
$date_query['inclusive'] = true;
|
||||
if ( isset( $_GET['start_date'] ) && '' != $_GET['start_date'] ) {
|
||||
$date_query['after'] = $_GET['start_date'];
|
||||
}
|
||||
if ( isset( $_GET['end_date'] ) && '' != $_GET['end_date'] ) {
|
||||
$date_query['before'] = $_GET['end_date'];
|
||||
}
|
||||
$args['date_query'] = array( $date_query );
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_module_deprecated' ) ) {
|
||||
/**
|
||||
* wcj_is_module_deprecated.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @return array|false
|
||||
*/
|
||||
function wcj_is_module_deprecated( $module_id, $by_module_option = false, $check_for_disabled = false ) {
|
||||
if ( $check_for_disabled ) {
|
||||
$module_option = ( $by_module_option ? $module_id : 'wcj_' . $module_id . '_enabled' );
|
||||
if ( 'yes' === get_option( $module_option, 'no' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( $by_module_option ) {
|
||||
$module_id = str_replace( array( 'wcj_', '_enabled' ), '', $module_id );
|
||||
}
|
||||
$deprecated_and_replacement_modules = array(
|
||||
'product_info' => array(
|
||||
'cat' => 'products',
|
||||
'module' => 'product_custom_info',
|
||||
'title' => __( 'Product Info', 'woocommerce-jetpack' ),
|
||||
),
|
||||
);
|
||||
if ( ! array_key_exists( $module_id, $deprecated_and_replacement_modules ) ) {
|
||||
return false;
|
||||
} else {
|
||||
return ( isset( $deprecated_and_replacement_modules[ $module_id ] ) ? $deprecated_and_replacement_modules[ $module_id ] : array() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_customer_get_country' ) ) {
|
||||
/**
|
||||
* wcj_customer_get_country.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
* @todo (maybe) move to `wcj-functions-users.php`
|
||||
*/
|
||||
function wcj_customer_get_country() {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ? WC()->customer->get_country() : WC()->customer->get_billing_country() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_customer_get_country_state' ) ) {
|
||||
/**
|
||||
* wcj_customer_get_country_state.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo (maybe) move to `wcj-functions-users.php`
|
||||
*/
|
||||
function wcj_customer_get_country_state() {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ? WC()->customer->get_state() : WC()->customer->get_billing_state() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_bot' ) ) {
|
||||
/**
|
||||
* wcj_is_bot.
|
||||
*
|
||||
* @version 2.5.7
|
||||
* @since 2.5.6
|
||||
*/
|
||||
function wcj_is_bot() {
|
||||
return ( isset( $_SERVER['HTTP_USER_AGENT'] ) && preg_match( '/Google-Structured-Data-Testing-Tool|bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'] ) ) ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_add_files_upload_form_to_checkout_frontend' ) ) {
|
||||
/**
|
||||
* wcj_add_files_upload_form_to_checkout_frontend.
|
||||
*
|
||||
* @version 2.5.2
|
||||
* @since 2.5.2
|
||||
*/
|
||||
function wcj_add_files_upload_form_to_checkout_frontend() {
|
||||
WCJ()->modules['checkout_files_upload']->add_files_upload_form_to_checkout_frontend_all( true );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_replace_values_in_template' ) ) {
|
||||
/**
|
||||
* wcj_replace_values_in_template.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_replace_values_in_template( $values_to_replace, $template ) {
|
||||
return str_replace( array_keys( $values_to_replace ), array_values( $values_to_replace ), $template );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_variation_radio_button' ) ) {
|
||||
/**
|
||||
* wcj_variation_radio_button.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 2.4.8
|
||||
* @todo (maybe) check - maybe we can use `$variation['variation_description']` instead of `get_post_meta( $variation_id, '_variation_description', true )`
|
||||
*/
|
||||
function wcj_variation_radio_button( $_product, $variation ) {
|
||||
$attributes_html = '';
|
||||
$variation_attributes_display_values = array();
|
||||
$is_checked = true;
|
||||
foreach ( $variation['attributes'] as $attribute_full_name => $attribute_value ) {
|
||||
$attributes_html .= ' ' . $attribute_full_name . '="' . $attribute_value . '"';
|
||||
// Attribute name
|
||||
$attribute_name = $attribute_full_name;
|
||||
$prefix = 'attribute_';
|
||||
if ( substr( $attribute_full_name, 0, strlen( $prefix ) ) === $prefix ) {
|
||||
$attribute_name = substr( $attribute_full_name, strlen( $prefix ) );
|
||||
}
|
||||
// Checked
|
||||
$checked = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ?
|
||||
wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $_product->get_variation_default_attribute( $attribute_name );
|
||||
if ( $checked != $attribute_value ) {
|
||||
$is_checked = false;
|
||||
}
|
||||
// Attribute value
|
||||
$terms = get_terms( $attribute_name );
|
||||
foreach ( $terms as $term ) {
|
||||
if ( is_object( $term ) && isset( $term->slug ) && $term->slug === $attribute_value && isset( $term->name ) ) {
|
||||
$attribute_value = $term->name;
|
||||
}
|
||||
}
|
||||
// Display values
|
||||
$variation_attributes_display_values[] = $attribute_value;
|
||||
}
|
||||
// Variation label
|
||||
$variation_label = wcj_replace_values_in_template( array(
|
||||
'%variation_title%' => implode( ', ', $variation_attributes_display_values ),
|
||||
'%variation_price%' => wc_price( $variation['display_price'] ),
|
||||
), get_option( 'wcj_add_to_cart_variable_as_radio_variation_label_template', '%variation_title% (%variation_price%)' ) );
|
||||
// Variation ID and "is checked"
|
||||
$variation_id = $variation['variation_id'];
|
||||
$is_checked = checked( $is_checked, true, false );
|
||||
// Final HTML
|
||||
$html = '';
|
||||
$html .= '<td class="wcj_variable_as_radio_input_td" style="' . get_option( 'wcj_add_to_cart_variable_as_radio_input_td_style', 'width:10%;' ) . '">';
|
||||
$html .= '<input id="wcj_variation_' . $variation_id . '" name="wcj_variations" type="radio"' . $attributes_html . ' variation_id="' .
|
||||
$variation_id . '"' . $is_checked . '>';
|
||||
$html .= '</td>';
|
||||
$html .= '<td class="wcj_variable_as_radio_label_td">';
|
||||
$html .= '<label for="wcj_variation_' . $variation_id . '">';
|
||||
$html .= $variation_label;
|
||||
if ( '' != ( $variation_description = get_post_meta( $variation_id, '_variation_description', true ) ) ) {
|
||||
$html .= wcj_replace_values_in_template( array(
|
||||
'%variation_description%' => $variation_description,
|
||||
), get_option( 'wcj_add_to_cart_variable_as_radio_variation_desc_template', '<br><small>%variation_description%</small>' ) );
|
||||
}
|
||||
$html .= '</label>';
|
||||
$html .= '</td>';
|
||||
echo $html;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_current_filter_priority' ) ) {
|
||||
/*
|
||||
* wcj_current_filter_priority.
|
||||
*
|
||||
* @version 2.5.8
|
||||
* @since 2.4.6
|
||||
*/
|
||||
function wcj_current_filter_priority() {
|
||||
global $wp_filter;
|
||||
$current_filter_data = $wp_filter[ current_filter() ];
|
||||
if ( class_exists( 'WP_Hook' ) && is_a( $current_filter_data, 'WP_Hook' ) ) {
|
||||
// since WordPress v4.7
|
||||
return $current_filter_data->current_priority();
|
||||
} else {
|
||||
// before WordPress v4.7
|
||||
return key( $current_filter_data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_implode' ) ) {
|
||||
/*
|
||||
* wcj_maybe_implode.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 3.2.1
|
||||
* @return string
|
||||
*/
|
||||
function wcj_maybe_implode( $value, $glue = ' ' ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$value = implode( $glue, $value );
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_unserialize_and_implode' ) ) {
|
||||
/*
|
||||
* wcj_maybe_unserialize_and_implode.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
* @return string
|
||||
* @todo `if ( ! is_array() )`
|
||||
*/
|
||||
function wcj_maybe_unserialize_and_implode( $value, $glue = ' ' ) {
|
||||
if ( is_serialized( $value ) ) {
|
||||
$value = unserialize( $value );
|
||||
if ( is_array( $value ) ) {
|
||||
$value = implode( $glue, $value );
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_cart_filters' ) ) {
|
||||
/*
|
||||
* wcj_get_cart_filters()
|
||||
*
|
||||
* @version 2.4.4
|
||||
* @since 2.4.4
|
||||
* @return array
|
||||
*/
|
||||
function wcj_get_cart_filters() {
|
||||
return array(
|
||||
'woocommerce_before_cart' => __( 'Before cart', 'woocommerce-jetpack' ),
|
||||
'woocommerce_before_cart_table' => __( 'Before cart table', 'woocommerce-jetpack' ),
|
||||
'woocommerce_before_cart_contents' => __( 'Before cart contents', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_contents' => __( 'Cart contents', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_coupon' => __( 'Cart coupon', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_actions' => __( 'Cart actions', 'woocommerce-jetpack' ),
|
||||
'woocommerce_after_cart_contents' => __( 'After cart contents', 'woocommerce-jetpack' ),
|
||||
'woocommerce_after_cart_table' => __( 'After cart table', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_collaterals' => __( 'Cart collaterals', 'woocommerce-jetpack' ),
|
||||
'woocommerce_after_cart' => __( 'After cart', 'woocommerce-jetpack' ),
|
||||
|
||||
'woocommerce_before_cart_totals' => __( 'Before cart totals', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_totals_before_shipping' => __( 'Cart totals: Before shipping', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_totals_after_shipping' => __( 'Cart totals: After shipping', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_totals_before_order_total' => __( 'Cart totals: Before order total', 'woocommerce-jetpack' ),
|
||||
'woocommerce_cart_totals_after_order_total' => __( 'Cart totals: After order total', 'woocommerce-jetpack' ),
|
||||
'woocommerce_proceed_to_checkout' => __( 'Proceed to checkout', 'woocommerce-jetpack' ),
|
||||
'woocommerce_after_cart_totals' => __( 'After cart totals', 'woocommerce-jetpack' ),
|
||||
|
||||
'woocommerce_before_shipping_calculator' => __( 'Before shipping calculator', 'woocommerce-jetpack' ),
|
||||
'woocommerce_after_shipping_calculator' => __( 'After shipping calculator', 'woocommerce-jetpack' ),
|
||||
|
||||
'woocommerce_cart_is_empty' => __( 'If cart is empty', 'woocommerce-jetpack' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_rates_for_tax_class' ) ) {
|
||||
/* Used by admin settings page.
|
||||
*
|
||||
* @param string $tax_class
|
||||
*
|
||||
* @return array|null|object
|
||||
*
|
||||
* @version 2.3.10
|
||||
* @since 2.3.10
|
||||
*/
|
||||
function wcj_get_rates_for_tax_class( $tax_class ) {
|
||||
global $wpdb;
|
||||
|
||||
// Get all the rates and locations. Snagging all at once should significantly cut down on the number of queries.
|
||||
$rates = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$wpdb->prefix}woocommerce_tax_rates` WHERE `tax_rate_class` = %s ORDER BY `tax_rate_order`;", sanitize_title( $tax_class ) ) );
|
||||
$locations = $wpdb->get_results( "SELECT * FROM `{$wpdb->prefix}woocommerce_tax_rate_locations`" );
|
||||
|
||||
// Set the rates keys equal to their ids.
|
||||
$rates = array_combine( wp_list_pluck( $rates, 'tax_rate_id' ), $rates );
|
||||
|
||||
// Drop the locations into the rates array.
|
||||
foreach ( $locations as $location ) {
|
||||
// Don't set them for unexistent rates.
|
||||
if ( ! isset( $rates[ $location->tax_rate_id ] ) ) {
|
||||
continue;
|
||||
}
|
||||
// If the rate exists, initialize the array before appending to it.
|
||||
if ( ! isset( $rates[ $location->tax_rate_id ]->{$location->location_type} ) ) {
|
||||
$rates[ $location->tax_rate_id ]->{$location->location_type} = array();
|
||||
}
|
||||
$rates[ $location->tax_rate_id ]->{$location->location_type}[] = $location->location_code;
|
||||
}
|
||||
|
||||
return $rates;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_select_options' ) ) {
|
||||
/*
|
||||
* wcj_get_select_options()
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.3.0
|
||||
* @return array
|
||||
*/
|
||||
function wcj_get_select_options( $select_options_raw, $do_sanitize = true ) {
|
||||
if ( '' === $select_options_raw ) {
|
||||
return array();
|
||||
}
|
||||
$select_options_raw = array_map( 'trim', explode( PHP_EOL, $select_options_raw ) );
|
||||
$select_options = array();
|
||||
foreach ( $select_options_raw as $select_options_title ) {
|
||||
$select_options_key = ( $do_sanitize ) ? sanitize_title( $select_options_title ) : $select_options_title;
|
||||
$select_options[ $select_options_key ] = $select_options_title;
|
||||
}
|
||||
return $select_options;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_frontend' ) ) {
|
||||
/*
|
||||
* is_frontend()
|
||||
*
|
||||
* @since 2.2.6
|
||||
* @return boolean
|
||||
*/
|
||||
function wcj_is_frontend() {
|
||||
return ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_wcj_uploads_dir' ) ) {
|
||||
/**
|
||||
* wcj_get_wcj_uploads_dir.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @todo no need to `mkdir` after `wcj_get_wcj_uploads_dir`
|
||||
*/
|
||||
function wcj_get_wcj_uploads_dir( $subdir = '' ) {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$upload_dir = $upload_dir['basedir'];
|
||||
$upload_dir = $upload_dir . '/woocommerce_uploads';
|
||||
if ( ! file_exists( $upload_dir ) ) {
|
||||
mkdir( $upload_dir, 0755, true );
|
||||
}
|
||||
$upload_dir = $upload_dir . '/wcj_uploads';
|
||||
if ( ! file_exists( $upload_dir ) ) {
|
||||
mkdir( $upload_dir, 0755, true );
|
||||
}
|
||||
if ( '' != $subdir ) {
|
||||
$upload_dir = $upload_dir . '/' . $subdir;
|
||||
if ( ! file_exists( $upload_dir ) ) {
|
||||
mkdir( $upload_dir, 0755, true );
|
||||
}
|
||||
}
|
||||
return $upload_dir;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_hex2rgb' ) ) {
|
||||
/**
|
||||
* wcj_hex2rgb.
|
||||
*/
|
||||
function wcj_hex2rgb( $hex ) {
|
||||
return sscanf( $hex, "#%2x%2x%2x" );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_the_ip' ) ) {
|
||||
/**
|
||||
* wcj_get_the_ip.
|
||||
*
|
||||
* @see http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
|
||||
*/
|
||||
function wcj_get_the_ip( ) {
|
||||
$ip = null;
|
||||
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
} else {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_shortcodes_list' ) ) {
|
||||
/**
|
||||
* wcj_get_shortcodes_list.
|
||||
*/
|
||||
function wcj_get_shortcodes_list() {
|
||||
$the_array = apply_filters( 'wcj_shortcodes_list', array() );
|
||||
return implode( ', ', $the_array )/* . ' (' . count( $the_array ) . ')' */;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - HTML Functions
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_table_html' ) ) {
|
||||
/**
|
||||
* wcj_get_table_html.
|
||||
*
|
||||
* @version 2.5.7
|
||||
*/
|
||||
function wcj_get_table_html( $data, $args = array() ) {
|
||||
$defaults = array(
|
||||
'table_class' => '',
|
||||
'table_style' => '',
|
||||
'row_styles' => '',
|
||||
'table_heading_type' => 'horizontal',
|
||||
'columns_classes' => array(),
|
||||
'columns_styles' => array(),
|
||||
);
|
||||
$args = array_merge( $defaults, $args );
|
||||
extract( $args );
|
||||
$table_class = ( '' == $table_class ) ? '' : ' class="' . $table_class . '"';
|
||||
$table_style = ( '' == $table_style ) ? '' : ' style="' . $table_style . '"';
|
||||
$row_styles = ( '' == $row_styles ) ? '' : ' style="' . $row_styles . '"';
|
||||
$html = '';
|
||||
$html .= '<table' . $table_class . $table_style . '>';
|
||||
$html .= '<tbody>';
|
||||
foreach( $data as $row_number => $row ) {
|
||||
$html .= '<tr' . $row_styles . '>';
|
||||
foreach( $row as $column_number => $value ) {
|
||||
$th_or_td = ( ( 0 === $row_number && 'horizontal' === $table_heading_type ) || ( 0 === $column_number && 'vertical' === $table_heading_type ) ) ? 'th' : 'td';
|
||||
$column_class = ( ! empty( $columns_classes ) && isset( $columns_classes[ $column_number ] ) ) ? ' class="' . $columns_classes[ $column_number ] . '"' : '';
|
||||
$column_style = ( ! empty( $columns_styles ) && isset( $columns_styles[ $column_number ] ) ) ? ' style="' . $columns_styles[ $column_number ] . '"' : '';
|
||||
|
||||
$html .= '<' . $th_or_td . $column_class . $column_style . '>';
|
||||
$html .= $value;
|
||||
$html .= '</' . $th_or_td . '>';
|
||||
}
|
||||
$html .= '</tr>';
|
||||
}
|
||||
$html .= '</tbody>';
|
||||
$html .= '</table>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_option_html' ) ) {
|
||||
/**
|
||||
* wcj_get_option_html.
|
||||
*
|
||||
* @version 3.3.0
|
||||
*/
|
||||
function wcj_get_option_html( $option_type, $option_id, $option_value, $option_description, $option_class ) {
|
||||
|
||||
if ( 'checkbox' === $option_type )
|
||||
$is_checked = checked( $option_value, 'on', false );
|
||||
|
||||
$html = '';
|
||||
switch ( $option_type ) {
|
||||
case 'number':
|
||||
case 'text':
|
||||
$html .= '<input type="' . $option_type . '" class="' . $option_class . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '">';
|
||||
break;
|
||||
case 'textarea':
|
||||
$html .= '<textarea class="' . $option_class . '" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</textarea>';
|
||||
break;
|
||||
case 'checkbox':
|
||||
$html .= '<input class="checkbox" style="margin-right:5px !important;" type="checkbox" name="' . $option_id . '" id="' . $option_id . '" ' . $is_checked . ' />';
|
||||
break;
|
||||
case 'select':
|
||||
$html .= '<select class="' . $option_class . '" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</select>';
|
||||
break;
|
||||
}
|
||||
$html .= '<span class="description">' . $option_description . '</span>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_empty_cart_button_html' ) ) {
|
||||
/**
|
||||
* wcj_empty_cart_button_html.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.8.0
|
||||
* @todo optional function parameters instead of default `get_option()` calls
|
||||
*/
|
||||
function wcj_empty_cart_button_html() {
|
||||
$confirmation_html = ( 'confirm_with_pop_up_box' == get_option( 'wcj_empty_cart_confirmation', 'no_confirmation' ) ) ?
|
||||
' onclick="return confirm(\'' . get_option( 'wcj_empty_cart_confirmation_text', __( 'Are you sure?', 'woocommerce-jetpack' ) ) . '\')"' : '';
|
||||
return '<div style="' . get_option( 'wcj_empty_cart_div_style', 'float: right;' ) . '">' .
|
||||
'<form action="" method="post"><input type="submit" class="' . get_option( 'wcj_empty_cart_button_class', 'button' ) . '" name="wcj_empty_cart" value="' .
|
||||
apply_filters( 'booster_option', 'Empty Cart', get_option( 'wcj_empty_cart_text', 'Empty Cart' ) ) . '"' . $confirmation_html . '>' .
|
||||
'</form>' .
|
||||
'</div>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,445 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Invoicing
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoicing_temp_dir' ) ) {
|
||||
/**
|
||||
* wcj_get_invoicing_temp_dir.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_get_invoicing_temp_dir() {
|
||||
return ( '' === ( $tmp_dir = get_option( 'wcj_invoicing_general_tmp_dir', '' ) ) ? sys_get_temp_dir() : $tmp_dir );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoicing_current_image_path_desc' ) ) {
|
||||
/**
|
||||
* wcj_get_invoicing_current_image_path_desc.
|
||||
*
|
||||
* @version 3.4.3
|
||||
* @since 3.4.3
|
||||
*/
|
||||
function wcj_get_invoicing_current_image_path_desc( $option_name ) {
|
||||
if ( '' != ( $current_image = get_option( $option_name, '' ) ) ) {
|
||||
if ( false !== ( $default_images_directory = wcj_get_invoicing_default_images_directory() ) ) {
|
||||
$image_path = $default_images_directory . parse_url( $current_image, PHP_URL_PATH );
|
||||
$style = ( file_exists( $image_path ) ? ' style="color:green;"' : '' );
|
||||
$current_image = '<br>' . sprintf( __( 'Current image path: %s.', 'woocommerce-jetpack' ), '<code' . $style . '>' . $image_path . '</code>' );
|
||||
} else {
|
||||
$current_image = '';
|
||||
}
|
||||
}
|
||||
return $current_image;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoicing_default_images_directory' ) ) {
|
||||
/**
|
||||
* wcj_get_invoicing_default_images_directory.
|
||||
*
|
||||
* @version 3.4.3
|
||||
* @since 3.4.2
|
||||
*/
|
||||
function wcj_get_invoicing_default_images_directory() {
|
||||
switch ( get_option( 'wcj_invoicing_general_header_images_path', 'document_root' ) ) {
|
||||
case 'empty':
|
||||
return '';
|
||||
case 'document_root':
|
||||
return $_SERVER['DOCUMENT_ROOT'];
|
||||
case 'abspath':
|
||||
return ABSPATH;
|
||||
default: // 'tcpdf_default'
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_fonts_list' ) ) {
|
||||
/**
|
||||
* wcj_get_fonts_list.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo (maybe) update existing fonts files
|
||||
* @todo (maybe) add more fonts
|
||||
*/
|
||||
function wcj_get_fonts_list() {
|
||||
return array(
|
||||
'angsanaupc.ctg.z',
|
||||
'angsanaupc.php',
|
||||
'angsanaupc.z',
|
||||
'angsanaupcb.ctg.z',
|
||||
'angsanaupcb.php',
|
||||
'angsanaupcb.z',
|
||||
'angsanaupcbi.ctg.z',
|
||||
'angsanaupcbi.php',
|
||||
'angsanaupcbi.z',
|
||||
'angsanaupci.ctg.z',
|
||||
'angsanaupci.php',
|
||||
'angsanaupci.z',
|
||||
'cid0ct.php',
|
||||
'cordiaupc.ctg.z',
|
||||
'cordiaupc.php',
|
||||
'cordiaupc.z',
|
||||
'cordiaupcb.ctg.z',
|
||||
'cordiaupcb.php',
|
||||
'cordiaupcb.z',
|
||||
'cordiaupcbi.ctg.z',
|
||||
'cordiaupcbi.php',
|
||||
'cordiaupcbi.z',
|
||||
'cordiaupci.ctg.z',
|
||||
'cordiaupci.php',
|
||||
'cordiaupci.z',
|
||||
'courier.php',
|
||||
'courierb.php',
|
||||
'courierbi.php',
|
||||
'courieri.php',
|
||||
'dejavusans.ctg.z',
|
||||
'dejavusans.php',
|
||||
'dejavusans.z',
|
||||
'dejavusansb.ctg.z',
|
||||
'dejavusansb.php',
|
||||
'dejavusansb.z',
|
||||
'dejavusansbi.ctg.z',
|
||||
'dejavusansbi.php',
|
||||
'dejavusansbi.z',
|
||||
'droidsansfallback.ctg.z',
|
||||
'droidsansfallback.php',
|
||||
'droidsansfallback.z',
|
||||
'helvetica.php',
|
||||
'helveticab.php',
|
||||
'helveticabi.php',
|
||||
'helveticai.php',
|
||||
'stsongstdlight.php',
|
||||
'symbol.php',
|
||||
'thsarabun.ctg.z',
|
||||
'thsarabun.php',
|
||||
'thsarabun.z',
|
||||
'thsarabunb.ctg.z',
|
||||
'thsarabunb.php',
|
||||
'thsarabunb.z',
|
||||
'thsarabunbi.ctg.z',
|
||||
'thsarabunbi.php',
|
||||
'thsarabunbi.z',
|
||||
'thsarabuni.ctg.z',
|
||||
'thsarabuni.php',
|
||||
'thsarabuni.z',
|
||||
'times.php',
|
||||
'timesb.php',
|
||||
'timesbi.php',
|
||||
'timesi.php',
|
||||
'uni2cid_aj16.php',
|
||||
'zapfdingbats.php',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_tcpdf_font' ) ) {
|
||||
/**
|
||||
* wcj_get_tcpdf_font.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_get_tcpdf_font( $invoice_type ) {
|
||||
return ( wcj_check_tcpdf_fonts_version( true ) ?
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_general_font_family', 'helvetica' ) :
|
||||
get_option( 'wcj_invoicing_' . $invoice_type . '_general_font_family_fallback', 'helvetica' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_tcpdf_fonts_version' ) ) {
|
||||
/**
|
||||
* wcj_get_tcpdf_fonts_version.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo (maybe) save old (i.e. fallback) versions
|
||||
*/
|
||||
function wcj_get_tcpdf_fonts_version() {
|
||||
return '2.9.0';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_tcpdf_fonts_version' ) ) {
|
||||
/**
|
||||
* wcj_check_tcpdf_fonts_version.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_check_tcpdf_fonts_version( $force_file_check = false ) {
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_fonts_manager_do_not_download', 'no' ) ) {
|
||||
return false;
|
||||
}
|
||||
$result = ( 0 == version_compare( get_option( 'wcj_invoicing_fonts_version', null ), wcj_get_tcpdf_fonts_version() ) );
|
||||
if ( $result && $force_file_check ) {
|
||||
$tcpdf_fonts_dir = wcj_get_wcj_uploads_dir( 'tcpdf_fonts' ) . '/';
|
||||
$tcpdf_fonts_dir_files = scandir( $tcpdf_fonts_dir );
|
||||
$tcpdf_fonts_files = wcj_get_fonts_list();
|
||||
foreach ( $tcpdf_fonts_files as $tcpdf_fonts_file ) {
|
||||
if ( ! in_array( $tcpdf_fonts_file, $tcpdf_fonts_dir_files ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_check_and_maybe_download_tcpdf_fonts' ) ) {
|
||||
/**
|
||||
* wcj_check_and_maybe_download_tcpdf_fonts.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.9.0
|
||||
* @todo (maybe) check file size > 0 or even for exact size (not only if file exists in directory)
|
||||
* @todo (maybe) use `download_url()` instead of `file_get_contents()` or `curl` (in all Booster files)
|
||||
*/
|
||||
function wcj_check_and_maybe_download_tcpdf_fonts( $force_download = false ) {
|
||||
if ( 'yes' === get_option( 'wcj_invoicing_fonts_manager_do_not_download', 'no' ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $force_download ) {
|
||||
if ( wcj_check_tcpdf_fonts_version( true ) ) {
|
||||
return true;
|
||||
}
|
||||
if ( ( (int) current_time( 'timestamp' ) - get_option( 'wcj_invoicing_fonts_version_timestamp', null ) ) < 60 * 60 ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
update_option( 'wcj_invoicing_fonts_version_timestamp', (int) current_time( 'timestamp' ) );
|
||||
$tcpdf_fonts_dir = wcj_get_wcj_uploads_dir( 'tcpdf_fonts' ) . '/';
|
||||
if ( ! file_exists( $tcpdf_fonts_dir ) ) {
|
||||
mkdir( $tcpdf_fonts_dir );
|
||||
}
|
||||
$tcpdf_fonts_dir_files = scandir( $tcpdf_fonts_dir );
|
||||
$tcpdf_fonts_files = wcj_get_fonts_list();
|
||||
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
||||
foreach ( $tcpdf_fonts_files as $tcpdf_fonts_file ) {
|
||||
if ( ! in_array( $tcpdf_fonts_file, $tcpdf_fonts_dir_files ) ) {
|
||||
$url = 'http://storage.booster.io/tcpdf_fonts/' . $tcpdf_fonts_file;
|
||||
if ( '.php' === substr( $tcpdf_fonts_file, -4 ) ) {
|
||||
$url .= '.data';
|
||||
}
|
||||
$response_file_name = download_url( $url );
|
||||
if ( ! is_wp_error( $response_file_name ) ) {
|
||||
if ( $response = file_get_contents( $response_file_name ) ) {
|
||||
if ( ! file_put_contents( $tcpdf_fonts_dir . $tcpdf_fonts_file, $response ) ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
unlink( $response_file_name );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
update_option( 'wcj_invoicing_fonts_version', wcj_get_tcpdf_fonts_version() ) &&
|
||||
update_option( 'wcj_invoicing_fonts_version_timestamp', (int) current_time( 'timestamp' ) )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoice_types' ) ) {
|
||||
/*
|
||||
* wcj_get_invoice_types.
|
||||
*
|
||||
* @version 3.4.0
|
||||
*/
|
||||
function wcj_get_invoice_types() {
|
||||
$invoice_types = array(
|
||||
array(
|
||||
'id' => 'invoice',
|
||||
'title' => get_option( 'wcj_invoicing_' . 'invoice' . '_admin_title', __( 'Invoice', 'woocommerce-jetpack' ) ),
|
||||
'defaults' => array( 'init' => 'disabled' ),
|
||||
'color' => 'green',
|
||||
),
|
||||
array(
|
||||
'id' => 'proforma_invoice',
|
||||
'title' => get_option( 'wcj_invoicing_' . 'proforma_invoice' . '_admin_title', __( 'Proforma Invoice', 'woocommerce-jetpack' ) ),
|
||||
'defaults' => array( 'init' => 'disabled' ),
|
||||
'color' => 'orange',
|
||||
),
|
||||
array(
|
||||
'id' => 'packing_slip',
|
||||
'title' => get_option( 'wcj_invoicing_' . 'packing_slip' . '_admin_title', __( 'Packing Slip', 'woocommerce-jetpack' ) ),
|
||||
'defaults' => array( 'init' => 'disabled' ),
|
||||
'color' => 'blue',
|
||||
),
|
||||
array(
|
||||
'id' => 'credit_note',
|
||||
'title' => get_option( 'wcj_invoicing_' . 'credit_note' . '_admin_title', __( 'Credit Note', 'woocommerce-jetpack' ) ),
|
||||
'defaults' => array( 'init' => 'disabled' ),
|
||||
'color' => 'red',
|
||||
),
|
||||
);
|
||||
$total_custom_docs = min( get_option( 'wcj_invoicing_custom_doc_total_number', 1 ), 100 );
|
||||
for ( $i = 1; $i <= $total_custom_docs; $i++ ) {
|
||||
$invoice_types[] = array(
|
||||
'id' => ( 1 == $i ? 'custom_doc' : 'custom_doc' . '_' . $i ),
|
||||
'title' => get_option( 'wcj_invoicing_' . ( 1 == $i ? 'custom_doc' : 'custom_doc' . '_' . $i ) . '_admin_title',
|
||||
__( 'Custom Document', 'woocommerce-jetpack' ) . ' #' . $i ),
|
||||
'defaults' => array( 'init' => 'disabled' ),
|
||||
'color' => 'gray',
|
||||
'is_custom_doc' => true,
|
||||
'custom_doc_nr' => $i,
|
||||
);
|
||||
}
|
||||
return $invoice_types;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoice_create_on' ) ) {
|
||||
/*
|
||||
* wcj_get_invoice_create_on.
|
||||
*
|
||||
* @version 3.2.0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
function wcj_get_invoice_create_on( $invoice_type ) {
|
||||
$create_on = get_option( 'wcj_invoicing_' . $invoice_type . '_create_on', '' );
|
||||
if ( empty( $create_on ) ) {
|
||||
return array();
|
||||
}
|
||||
if ( ! is_array( $create_on ) ) {
|
||||
// Backward compatibility with Booster version <= 3.1.3
|
||||
if ( 'disabled' === $create_on ) {
|
||||
update_option( 'wcj_invoicing_' . $invoice_type . '_create_on', '' );
|
||||
return array();
|
||||
} elseif ( 'wcj_pdf_invoicing_create_on_any_refund' === $create_on ) {
|
||||
$create_on = array( 'woocommerce_order_status_refunded', 'woocommerce_order_partially_refunded_notification' );
|
||||
update_option( 'wcj_invoicing_' . $invoice_type . '_create_on', $create_on );
|
||||
return $create_on;
|
||||
} else {
|
||||
$create_on = array( $create_on );
|
||||
update_option( 'wcj_invoicing_' . $invoice_type . '_create_on', $create_on );
|
||||
return $create_on;
|
||||
}
|
||||
}
|
||||
return $create_on;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_enabled_invoice_types' ) ) {
|
||||
/*
|
||||
* wcj_get_enabled_invoice_types.
|
||||
*
|
||||
* @version 3.2.0
|
||||
*/
|
||||
function wcj_get_enabled_invoice_types() {
|
||||
$invoice_types = wcj_get_invoice_types();
|
||||
$enabled_invoice_types = array();
|
||||
foreach ( $invoice_types as $k => $invoice_type ) {
|
||||
$z = ( 0 === $k ) ? wcj_get_invoice_create_on( $invoice_type['id'] ) : apply_filters( 'booster_option', '', wcj_get_invoice_create_on( $invoice_type['id'] ) );
|
||||
if ( empty( $z ) ) {
|
||||
continue;
|
||||
}
|
||||
$enabled_invoice_types[] = $invoice_type;
|
||||
}
|
||||
return $enabled_invoice_types;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_enabled_invoice_types_ids' ) ) {
|
||||
/*
|
||||
* wcj_get_enabled_invoice_types_ids.
|
||||
*/
|
||||
function wcj_get_enabled_invoice_types_ids() {
|
||||
$invoice_types = wcj_get_enabled_invoice_types();
|
||||
$invoice_types_ids = array();
|
||||
foreach( $invoice_types as $invoice_type ) {
|
||||
$invoice_types_ids[] = $invoice_type['id'];
|
||||
}
|
||||
return $invoice_types_ids;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_pdf_invoice' ) ) {
|
||||
/*
|
||||
* wcj_get_pdf_invoice.
|
||||
*/
|
||||
function wcj_get_pdf_invoice( $order_id, $invoice_type_id ) {
|
||||
$the_invoice = new WCJ_PDF_Invoice( $order_id, $invoice_type_id );
|
||||
return $the_invoice;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoice' ) ) {
|
||||
/*
|
||||
* wcj_get_invoice.
|
||||
*/
|
||||
function wcj_get_invoice( $order_id, $invoice_type_id ) {
|
||||
$the_invoice = new WCJ_Invoice( $order_id, $invoice_type_id );
|
||||
return $the_invoice;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoice_date' ) ) {
|
||||
/*
|
||||
* wcj_get_invoice_date.
|
||||
*
|
||||
* @version 2.9.0
|
||||
*/
|
||||
function wcj_get_invoice_date( $order_id, $invoice_type_id, $extra_days, $date_format ) {
|
||||
$the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
|
||||
if ( $invoice_date_timestamp = $the_invoice->get_invoice_date() ) {
|
||||
$extra_days_in_sec = $extra_days * 24 * 60 * 60;
|
||||
return date_i18n( $date_format, $invoice_date_timestamp + $extra_days_in_sec );
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_invoice_number' ) ) {
|
||||
/*
|
||||
* wcj_get_invoice_number.
|
||||
*/
|
||||
function wcj_get_invoice_number( $order_id, $invoice_type_id ) {
|
||||
$the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
|
||||
return $the_invoice->get_invoice_number();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_delete_invoice' ) ) {
|
||||
/*
|
||||
* wcj_delete_invoice.
|
||||
*/
|
||||
function wcj_delete_invoice( $order_id, $invoice_type_id ) {
|
||||
$the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
|
||||
$the_invoice->delete();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_create_invoice' ) ) {
|
||||
/*
|
||||
* wcj_create_invoice.
|
||||
*/
|
||||
function wcj_create_invoice( $order_id, $invoice_type_id, $date = '' ) {
|
||||
$the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
|
||||
$the_invoice->create( $date );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_invoice_created' ) ) {
|
||||
/*
|
||||
* wcj_is_invoice_created.
|
||||
*/
|
||||
function wcj_is_invoice_created( $order_id, $invoice_type_id ) {
|
||||
$the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
|
||||
return $the_invoice->is_created();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Math
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_round' ) ) {
|
||||
/**
|
||||
* wcj_round.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function wcj_round( $value, $precision = 0, $rounding_function = 'round' ) {
|
||||
return $rounding_function( $value, $precision );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_ceil' ) ) {
|
||||
/**
|
||||
* wcj_ceil.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function wcj_ceil( $value, $precision = 0 ) {
|
||||
$fig = ( int ) str_pad( '1', $precision + 1, '0' );
|
||||
return ( ceil( $value * $fig ) / $fig );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_floor' ) ) {
|
||||
/**
|
||||
* wcj_floor.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function wcj_floor( $value, $precision = 0 ) {
|
||||
$fig = ( int ) str_pad( '1', $precision + 1, '0' );
|
||||
return ( floor( $value * $fig ) / $fig );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Numbers to Words - BG
|
||||
*
|
||||
* @version 2.5.9
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'convert_number_to_words_bg' ) ) {
|
||||
/**
|
||||
* convert_number_to_words_bg.
|
||||
*
|
||||
* @version 2.5.9
|
||||
* @return string
|
||||
*/
|
||||
function convert_number_to_words_bg( $num, $tri = 0 ) {
|
||||
$edinici = array(
|
||||
0 => "",
|
||||
1 => array(
|
||||
0 => " един",
|
||||
1 => "",
|
||||
2 => " eдин",
|
||||
3 => " eдин",
|
||||
4 => " eдин",
|
||||
5 => " eдин",
|
||||
6 => " eдин",
|
||||
7 => " eдин",
|
||||
8 => " eдин",
|
||||
9 => " eдин",
|
||||
10 => " eдин",
|
||||
),
|
||||
2 => array(
|
||||
0 => " два",
|
||||
1 => " двe",
|
||||
2 => " два",
|
||||
3 => " два",
|
||||
4 => " два",
|
||||
5 => " два",
|
||||
6 => " два",
|
||||
7 => " два",
|
||||
8 => " два",
|
||||
9 => " два",
|
||||
10 => " два",
|
||||
),
|
||||
3 => " три",
|
||||
4 => " четири",
|
||||
5 => " пет",
|
||||
6 => " шест",
|
||||
7 => " седем",
|
||||
8 => " осем",
|
||||
9 => " девет",
|
||||
10 => " десет",
|
||||
11 => " единадесет",
|
||||
12 => " дванадесет",
|
||||
13 => " тринадесет",
|
||||
14 => " четиринадесет",
|
||||
15 => " петнадесет",
|
||||
16 => " шестнадесет",
|
||||
17 => " седемнадесет",
|
||||
18 => " осемнадесет",
|
||||
19 => " деветнадесет"
|
||||
);
|
||||
|
||||
$desetici = array(
|
||||
0 => "",
|
||||
1 => "",
|
||||
2 => " двадесет",
|
||||
3 => " тридесет",
|
||||
4 => " четиридесет",
|
||||
5 => " петдесет",
|
||||
6 => " шестдесет",
|
||||
7 => " седемдесет",
|
||||
8 => " осемдесет",
|
||||
9 => " деведесет"
|
||||
);
|
||||
|
||||
$stotici = array (
|
||||
0 => "",
|
||||
1 => " сто",
|
||||
2 => " двеста",
|
||||
3 => " триста",
|
||||
4 => " четиристотин",
|
||||
5 => " петстотин",
|
||||
6 => " шестстотин",
|
||||
7 => " седемстотин",
|
||||
8 => " осемстотин",
|
||||
9 => " деветстотин",
|
||||
);
|
||||
|
||||
$tripleti = array(
|
||||
0 => "",
|
||||
1 => array(
|
||||
0 => " хиляда",
|
||||
1 => " хиляди"),
|
||||
2 => array(
|
||||
0 => " милион",
|
||||
1 => " милиона"),
|
||||
3 => array(
|
||||
0 => " билион",
|
||||
1 => " билионa"),
|
||||
4 => array(
|
||||
0 => " трилион",
|
||||
1 => " трилиона"),
|
||||
5 => array(
|
||||
0 => " квадрилион",
|
||||
1 => " квадрилиона"),
|
||||
6 => array(
|
||||
0 => " квинтилион",
|
||||
1 => " квинтилиони"),
|
||||
7 => array(
|
||||
0 => " сикстилион",
|
||||
1 => " сикстилион"),
|
||||
8 => array(
|
||||
0 => " септилион",
|
||||
1 => " септилиони"),
|
||||
9 => array(
|
||||
0 => " октилион",
|
||||
1 => " октилион"),
|
||||
10 => array(
|
||||
0 => " нонилион",
|
||||
1 => " нонилиои")
|
||||
);
|
||||
|
||||
//взимаме само цялата част от числото, без стойността
|
||||
//след десетичната запетая
|
||||
$n = explode(".", $num);
|
||||
$num = $n[0];
|
||||
$r = (int) ($num / 1000);
|
||||
$x = ($num / 100) % 10;
|
||||
$y = $num % 100;
|
||||
|
||||
$str = "";
|
||||
|
||||
// стотици
|
||||
if ($x > 0) {
|
||||
$str = $stotici[$x];
|
||||
}
|
||||
// единици и десетици
|
||||
if ($y < 20) {
|
||||
if($y == 0 && $r > 0) {
|
||||
$str = ' и '.$str;
|
||||
}
|
||||
if(is_array($edinici[$y]) && isset($edinici[$y][$tri])) {
|
||||
$str .= ' '.$edinici[$y][$tri];
|
||||
}
|
||||
else {
|
||||
$str .= ' '.$edinici[$y];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if($edinici[$y % 10]) {
|
||||
$str .= $desetici[(int) ($y / 10)];
|
||||
$str .= ' и';
|
||||
if(is_array($edinici[$y % 10]) && isset($edinici[$y % 10][$tri])) {
|
||||
$str .= $edinici[$y % 10][$tri];
|
||||
}
|
||||
else {
|
||||
$str .= $edinici[$y % 10];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$str .= ' и'.$desetici[(int) ($y / 10)];
|
||||
}
|
||||
}
|
||||
|
||||
// добавяне на модификатор - хиляди, милиони, билиони
|
||||
|
||||
if ($str != "") {
|
||||
//Ако има зададени опции за единствено и мн. число
|
||||
if(is_array($tripleti[$tri])) {
|
||||
//мн. число ли е?
|
||||
if($num > 1) {
|
||||
$str .= $tripleti[$tri][1];
|
||||
}
|
||||
else {
|
||||
$str .= $tripleti[$tri][0];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$str .= $tripleti[$tri];
|
||||
}
|
||||
$str = str_replace('един стотин', 'сто', $str);
|
||||
$str = str_replace('един хиляди', 'хиляда', $str);
|
||||
}
|
||||
|
||||
//ако сме на първата стъпка (т.е. определяме числото до стотици)
|
||||
/* if($tri == 0) {
|
||||
//добавяме префикс за лева
|
||||
$str .= ' лева';
|
||||
//и ако има сетнати стотинки ги добавяме и тях
|
||||
if(isset($n[1])) {
|
||||
$str .= ' и '.$n[1].'ст.';
|
||||
}
|
||||
} */
|
||||
|
||||
// продължаване рекрусивно?
|
||||
if ($r > 0) {
|
||||
return convert_number_to_words_bg($r, $tri+1).$str;
|
||||
}
|
||||
else {
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Numbers to Words
|
||||
*
|
||||
* @version 2.5.9
|
||||
* @since 2.5.9
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'convert_number_to_words_lt' ) ) {
|
||||
/**
|
||||
* convert_number_to_words_lt.
|
||||
*
|
||||
* @version 2.5.9
|
||||
* @since 2.5.9
|
||||
* @return string
|
||||
*/
|
||||
function convert_number_to_words_lt( $number ) {
|
||||
$hyphen = ' ';
|
||||
$conjunction = ' ';
|
||||
$separator = ', ';
|
||||
$negative = 'minus ';
|
||||
$decimal = ' . ';
|
||||
$dictionary = array(
|
||||
0 => 'nulis',
|
||||
1 => 'vienas',
|
||||
2 => 'du',
|
||||
3 => 'trys',
|
||||
4 => 'keturi',
|
||||
5 => 'penki',
|
||||
6 => 'šeši',
|
||||
7 => 'septyni',
|
||||
8 => 'aštuoni',
|
||||
9 => 'devyni',
|
||||
10 => 'dešimt',
|
||||
11 => 'vienuolika',
|
||||
12 => 'dvylika',
|
||||
13 => 'trylika',
|
||||
14 => 'keturiolika',
|
||||
15 => 'penkiolika',
|
||||
16 => 'šešiolika',
|
||||
17 => 'septyniolika',
|
||||
18 => 'aštoniolika',
|
||||
19 => 'devyniolika',
|
||||
20 => 'dvidešimt',
|
||||
30 => 'trisdešimt',
|
||||
40 => 'keturiasdešimt',
|
||||
50 => 'penkiasdešimt',
|
||||
60 => 'šešiasdešimt',
|
||||
70 => 'septyniasdešimt',
|
||||
80 => 'aštuoniasdešimt',
|
||||
90 => 'devyniasdešimt',
|
||||
100 => 'šimtas',
|
||||
200 => 'šimtai',
|
||||
1000 => 'tūkstantis',
|
||||
2000 => 'tūkstančiai',
|
||||
10000 => 'tūkstančių',
|
||||
1000000 => 'milijonas',
|
||||
2000000 => 'milijonai',
|
||||
10000000 => 'milijonų',
|
||||
1000000000 => 'bilijonas',
|
||||
2000000000 => 'bilijonai',
|
||||
10000000000 => 'bilijonų',
|
||||
1000000000000 => 'trilijonas',
|
||||
2000000000000 => 'trilijonai',
|
||||
10000000000000 => 'trilijonų',
|
||||
1000000000000000 => 'kvadrilijonas',
|
||||
2000000000000000 => 'kvadrilijonai',
|
||||
10000000000000000 => 'kvadrilijonų',
|
||||
1000000000000000000 => 'kvintilijonas',
|
||||
2000000000000000000 => 'kvintilijonai',
|
||||
10000000000000000000 => 'kvintilijonų',
|
||||
);
|
||||
|
||||
if (!is_numeric($number)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
|
||||
// overflow
|
||||
trigger_error(
|
||||
'convert_number_to_words_lt only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
|
||||
E_USER_WARNING
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($number < 0) {
|
||||
return $negative . convert_number_to_words_lt(abs($number));
|
||||
}
|
||||
|
||||
$string = $fraction = null;
|
||||
|
||||
if (strpos($number, '.') !== false) {
|
||||
list($number, $fraction) = explode('.', $number);
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case $number < 21:
|
||||
$string = $dictionary[$number];
|
||||
break;
|
||||
case $number < 100:
|
||||
$tens = ((int) ($number / 10)) * 10;
|
||||
$units = $number % 10;
|
||||
$string = $dictionary[$tens];
|
||||
if ($units) {
|
||||
$string .= $hyphen . $dictionary[$units];
|
||||
}
|
||||
break;
|
||||
case $number < 200:
|
||||
$hundreds = $number / 100;
|
||||
$remainder = $number % 100;
|
||||
$string = $dictionary[$hundreds] . ' ' . $dictionary[100];
|
||||
if ($remainder) {
|
||||
$string .= $conjunction . convert_number_to_words_lt($remainder);
|
||||
}
|
||||
break;
|
||||
case $number < 1000:
|
||||
$hundreds = $number / 100;
|
||||
$remainder = $number % 100;
|
||||
$string = $dictionary[$hundreds] . ' ' . $dictionary[200];
|
||||
if ($remainder) {
|
||||
$string .= $conjunction . convert_number_to_words_lt($remainder);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$baseUnit = pow(1000, floor(log($number, 1000)));
|
||||
$numBaseUnits = (int) ($number / $baseUnit);
|
||||
$number1=(string)$number;
|
||||
if ($numBaseUnits==1){
|
||||
$baseUnits=$baseUnit;
|
||||
}elseif($numBaseUnits <10) {
|
||||
$baseUnits=$baseUnit*2;
|
||||
} else {
|
||||
$baseUnits=$baseUnit*10;}
|
||||
|
||||
$remainder = $number % $baseUnit;
|
||||
$string = convert_number_to_words_lt($numBaseUnits) . ' ' . $dictionary[$baseUnits];
|
||||
if ($remainder) {
|
||||
$string .= $remainder < 100 ? $conjunction : $separator;
|
||||
$string .= convert_number_to_words_lt($remainder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (null !== $fraction && is_numeric($fraction)) {
|
||||
$string .= $decimal;
|
||||
$words = array();
|
||||
foreach (str_split((string) $fraction) as $number) {
|
||||
$words[] = $dictionary[$number];
|
||||
}
|
||||
$string .= implode(' ', $words);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Numbers to Words
|
||||
*
|
||||
* @version 2.5.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
/**
|
||||
* convert_number_to_words.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
if ( ! function_exists( 'convert_number_to_words' ) ) {
|
||||
function convert_number_to_words( $number ) {
|
||||
$hyphen = '-';
|
||||
$conjunction = ' and ';
|
||||
$separator = ', ';
|
||||
$negative = 'negative ';
|
||||
$decimal = ' point ';
|
||||
$dictionary = array(
|
||||
0 => 'zero',
|
||||
1 => 'one',
|
||||
2 => 'two',
|
||||
3 => 'three',
|
||||
4 => 'four',
|
||||
5 => 'five',
|
||||
6 => 'six',
|
||||
7 => 'seven',
|
||||
8 => 'eight',
|
||||
9 => 'nine',
|
||||
10 => 'ten',
|
||||
11 => 'eleven',
|
||||
12 => 'twelve',
|
||||
13 => 'thirteen',
|
||||
14 => 'fourteen',
|
||||
15 => 'fifteen',
|
||||
16 => 'sixteen',
|
||||
17 => 'seventeen',
|
||||
18 => 'eighteen',
|
||||
19 => 'nineteen',
|
||||
20 => 'twenty',
|
||||
30 => 'thirty',
|
||||
40 => 'fourty',
|
||||
50 => 'fifty',
|
||||
60 => 'sixty',
|
||||
70 => 'seventy',
|
||||
80 => 'eighty',
|
||||
90 => 'ninety',
|
||||
100 => 'hundred',
|
||||
1000 => 'thousand',
|
||||
1000000 => 'million',
|
||||
1000000000 => 'billion',
|
||||
1000000000000 => 'trillion',
|
||||
1000000000000000 => 'quadrillion',
|
||||
1000000000000000000 => 'quintillion'
|
||||
);
|
||||
|
||||
if (!is_numeric($number)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
|
||||
// overflow
|
||||
trigger_error(
|
||||
'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
|
||||
E_USER_WARNING
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($number < 0) {
|
||||
return $negative . convert_number_to_words(abs($number));
|
||||
}
|
||||
|
||||
$string = $fraction = null;
|
||||
|
||||
if (strpos($number, '.') !== false) {
|
||||
list($number, $fraction) = explode('.', $number);
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case $number < 21:
|
||||
$string = $dictionary[$number];
|
||||
break;
|
||||
case $number < 100:
|
||||
$tens = ((int) ($number / 10)) * 10;
|
||||
$units = $number % 10;
|
||||
$string = $dictionary[$tens];
|
||||
if ($units) {
|
||||
$string .= $hyphen . $dictionary[$units];
|
||||
}
|
||||
break;
|
||||
case $number < 1000:
|
||||
$hundreds = $number / 100;
|
||||
$remainder = $number % 100;
|
||||
$string = $dictionary[$hundreds] . ' ' . $dictionary[100];
|
||||
if ($remainder) {
|
||||
$string .= $conjunction . convert_number_to_words($remainder);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$baseUnit = pow(1000, floor(log($number, 1000)));
|
||||
$numBaseUnits = (int) ($number / $baseUnit);
|
||||
$remainder = $number % $baseUnit;
|
||||
$string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
|
||||
if ($remainder) {
|
||||
$string .= $remainder < 100 ? $conjunction : $separator;
|
||||
$string .= convert_number_to_words($remainder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (null !== $fraction && is_numeric($fraction)) {
|
||||
$string .= $decimal;
|
||||
$words = array();
|
||||
foreach (str_split((string) $fraction) as $number) {
|
||||
$words[] = $dictionary[$number];
|
||||
}
|
||||
$string .= implode(' ', $words);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Orders
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_adjacent_order_id' ) ) {
|
||||
/**
|
||||
* wcj_get_adjacent_order_id.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 3.4.0
|
||||
* @todo isn't there an easier way?
|
||||
*/
|
||||
function wcj_get_adjacent_order_id( $current_id, $direction = 'next' ) {
|
||||
$args = array(
|
||||
'post_type' => 'shop_order',
|
||||
'post_status' => array_keys( wc_get_order_statuses() ),
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'ASC',
|
||||
'fields' => 'ids',
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
if ( $loop->have_posts() ) {
|
||||
foreach ( $loop->posts as $post_id ) {
|
||||
if ( $current_id == $post_id ) {
|
||||
return $direction( $loop->posts );
|
||||
}
|
||||
next( $loop->posts );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_status' ) ) {
|
||||
/**
|
||||
* wcj_get_order_status.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 3.2.2
|
||||
*/
|
||||
function wcj_get_order_status( $_order ) {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ? $_order->post_status : $_order->get_status() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_billing_email' ) ) {
|
||||
/**
|
||||
* wcj_get_order_billing_email.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_get_order_billing_email( $_order ) {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ? $_order->billing_email : $_order->get_billing_email() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_date' ) ) {
|
||||
/**
|
||||
* wcj_get_order_date.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_get_order_date( $_order ) {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ? $_order->order_date : $_order->get_date_created() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_id' ) ) {
|
||||
/**
|
||||
* wcj_get_order_id.
|
||||
*
|
||||
* @version 3.1.1
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_order_id( $_order ) {
|
||||
if ( ! $_order || ! is_object( $_order ) ) {
|
||||
return 0;
|
||||
}
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ) ? $_order->id : $_order->get_id();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_currency' ) ) {
|
||||
/**
|
||||
* wcj_get_order_currency.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_order_currency( $_order ) {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ? $_order->get_order_currency() : $_order->get_currency() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_item_meta_info' ) ) {
|
||||
/**
|
||||
* wcj_get_order_item_meta_info.
|
||||
*
|
||||
* from woocommerce\includes\admin\meta-boxes\views\html-order-item-meta.php
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 2.5.9
|
||||
*/
|
||||
function wcj_get_order_item_meta_info( $item_id, $item, $_order, $exclude_wcj_meta = false, $_product = null, $exclude_meta = array() ) {
|
||||
$meta_info = '';
|
||||
$metadata = ( WCJ_IS_WC_VERSION_BELOW_3 ? $_order->has_meta( $item_id ) : $item->get_meta_data() );
|
||||
if ( $metadata ) {
|
||||
$meta_info = array();
|
||||
foreach ( $metadata as $meta ) {
|
||||
|
||||
$_meta_key = ( WCJ_IS_WC_VERSION_BELOW_3 ? $meta['meta_key'] : $meta->key );
|
||||
$_meta_value = ( WCJ_IS_WC_VERSION_BELOW_3 ? $meta['meta_value'] : $meta->value );
|
||||
|
||||
// Skip hidden core fields
|
||||
if ( in_array( $_meta_key, apply_filters( 'woocommerce_hidden_order_itemmeta', array(
|
||||
'_qty',
|
||||
'_tax_class',
|
||||
'_product_id',
|
||||
'_variation_id',
|
||||
'_line_subtotal',
|
||||
'_line_subtotal_tax',
|
||||
'_line_total',
|
||||
'_line_tax',
|
||||
'method_id',
|
||||
'cost'
|
||||
) ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! empty( $exclude_meta ) && in_array( $_meta_key, $exclude_meta ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $exclude_wcj_meta && ( 'wcj' === substr( $_meta_key, 0, 3 ) || '_wcj' === substr( $_meta_key, 0, 4 ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $exclude_wcj_meta && 'is_custom' === $_meta_key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip serialised meta
|
||||
if ( is_serialized( $_meta_value ) || is_array( $_meta_value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get attribute data
|
||||
if ( taxonomy_exists( wc_sanitize_taxonomy_name( $_meta_key ) ) ) {
|
||||
$term = get_term_by( 'slug', $_meta_value, wc_sanitize_taxonomy_name( $_meta_key ) );
|
||||
$_meta_key = wc_attribute_label( wc_sanitize_taxonomy_name( $_meta_key ) );
|
||||
$_meta_value = isset( $term->name ) ? $term->name : $_meta_value;
|
||||
} else {
|
||||
$the_product = null;
|
||||
if ( is_object( $_product ) ) {
|
||||
$the_product = $_product;
|
||||
} elseif ( is_object( $item ) ) {
|
||||
$the_product = $_order->get_product_from_item( $item );
|
||||
}
|
||||
$_meta_key = ( is_object( $the_product ) ) ? wc_attribute_label( $_meta_key, $the_product ) : $_meta_key;
|
||||
}
|
||||
$meta_info[] = wp_kses_post( rawurldecode( $_meta_key ) ) . ': ' . wp_kses_post( rawurldecode( $_meta_value ) );
|
||||
}
|
||||
$meta_info = implode( ', ', $meta_info );
|
||||
}
|
||||
return $meta_info;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_order_statuses' ) ) {
|
||||
/**
|
||||
* wcj_get_order_statuses.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_get_order_statuses( $cut_prefix = true ) {
|
||||
$statuses = function_exists( 'wc_get_order_statuses' ) ? wc_get_order_statuses() : array();
|
||||
if ( ! $cut_prefix ) {
|
||||
return $statuses;
|
||||
}
|
||||
$result = array();
|
||||
foreach( $statuses as $status => $status_name ) {
|
||||
$result[ substr( $status, 3 ) ] = $status_name;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_order_get_payment_method' ) ) {
|
||||
/**
|
||||
* wcj_order_get_payment_method.
|
||||
*
|
||||
* @version 2.8.2
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_order_get_payment_method( $_order ) {
|
||||
if ( ! $_order || ! is_object( $_order ) ) {
|
||||
return null;
|
||||
}
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
return ( isset( $_order->payment_method ) ? $_order->payment_method : null );
|
||||
} else {
|
||||
return ( method_exists( $_order, 'get_payment_method' ) ? $_order->get_payment_method() : null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,579 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Price and Currency
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_wc_price_step' ) ) {
|
||||
/**
|
||||
* wcj_get_wc_price_step.
|
||||
*
|
||||
* @version 3.2.3
|
||||
* @since 3.2.3
|
||||
* @todo use this where needed
|
||||
*/
|
||||
function wcj_get_wc_price_step() {
|
||||
return ( 1 / pow( 10, absint( get_option( 'woocommerce_price_num_decimals', 2 ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_module_price_hooks_priority' ) ) {
|
||||
/**
|
||||
* wcj_get_module_price_hooks_priority.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.2.2
|
||||
* @todo add all corresponding modules
|
||||
*/
|
||||
function wcj_get_module_price_hooks_priority( $module_id ) {
|
||||
$modules_priorities = array(
|
||||
'price_by_country' => PHP_INT_MAX - 1,
|
||||
'multicurrency' => PHP_INT_MAX - 1,
|
||||
'price_by_user_role' => PHP_INT_MAX - 200,
|
||||
);
|
||||
return ( 0 != ( $priority = get_option( 'wcj_' . $module_id . '_advanced_price_hooks_priority', 0 ) ) ? $priority : $modules_priorities[ $module_id ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_add_change_price_hooks' ) ) {
|
||||
/**
|
||||
* wcj_add_change_price_hooks.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.7.0
|
||||
* @todo use `$module_object->price_hooks_priority` instead of passing `$priority` argument
|
||||
*/
|
||||
function wcj_add_change_price_hooks( $module_object, $priority, $include_shipping = true ) {
|
||||
// Prices
|
||||
add_filter( WCJ_PRODUCT_GET_PRICE_FILTER, array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( WCJ_PRODUCT_GET_SALE_PRICE_FILTER, array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( WCJ_PRODUCT_GET_REGULAR_PRICE_FILTER, array( $module_object, 'change_price' ), $priority, 2 );
|
||||
// Variations
|
||||
add_filter( 'woocommerce_variation_prices_price', array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( 'woocommerce_variation_prices_regular_price', array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( 'woocommerce_variation_prices_sale_price', array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( 'woocommerce_get_variation_prices_hash', array( $module_object, 'get_variation_prices_hash' ), $priority, 3 );
|
||||
if ( ! WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
add_filter( 'woocommerce_product_variation_get_price', array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( 'woocommerce_product_variation_get_regular_price', array( $module_object, 'change_price' ), $priority, 2 );
|
||||
add_filter( 'woocommerce_product_variation_get_sale_price', array( $module_object, 'change_price' ), $priority, 2 );
|
||||
}
|
||||
// Shipping
|
||||
if ( $include_shipping ) {
|
||||
add_filter( 'woocommerce_package_rates', array( $module_object, 'change_price_shipping' ), $priority, 2 );
|
||||
}
|
||||
// Grouped products
|
||||
add_filter( 'woocommerce_get_price_including_tax', array( $module_object, 'change_price_grouped' ), $priority, 3 );
|
||||
add_filter( 'woocommerce_get_price_excluding_tax', array( $module_object, 'change_price_grouped' ), $priority, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_remove_change_price_hooks' ) ) {
|
||||
/**
|
||||
* wcj_remove_change_price_hooks.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
* @todo make one function from this and `wcj_add_change_price_hooks()`
|
||||
*/
|
||||
function wcj_remove_change_price_hooks( $module_object, $priority, $include_shipping = true ) {
|
||||
// Prices
|
||||
remove_filter( WCJ_PRODUCT_GET_PRICE_FILTER, array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( WCJ_PRODUCT_GET_SALE_PRICE_FILTER, array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( WCJ_PRODUCT_GET_REGULAR_PRICE_FILTER, array( $module_object, 'change_price' ), $priority );
|
||||
// Variations
|
||||
remove_filter( 'woocommerce_variation_prices_price', array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( 'woocommerce_variation_prices_regular_price', array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( 'woocommerce_variation_prices_sale_price', array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( 'woocommerce_get_variation_prices_hash', array( $module_object, 'get_variation_prices_hash' ), $priority );
|
||||
if ( ! WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
remove_filter( 'woocommerce_product_variation_get_price', array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( 'woocommerce_product_variation_get_regular_price', array( $module_object, 'change_price' ), $priority );
|
||||
remove_filter( 'woocommerce_product_variation_get_sale_price', array( $module_object, 'change_price' ), $priority );
|
||||
}
|
||||
// Shipping
|
||||
if ( $include_shipping ) {
|
||||
remove_filter( 'woocommerce_package_rates', array( $module_object, 'change_price_shipping' ), $priority );
|
||||
}
|
||||
// Grouped products
|
||||
remove_filter( 'woocommerce_get_price_including_tax', array( $module_object, 'change_price_grouped' ), $priority );
|
||||
remove_filter( 'woocommerce_get_price_excluding_tax', array( $module_object, 'change_price_grouped' ), $priority );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_change_price_shipping_package_rates' ) ) {
|
||||
/**
|
||||
* wcj_change_price_shipping_package_rates.
|
||||
*
|
||||
* @version 3.2.0
|
||||
* @since 3.2.0
|
||||
*/
|
||||
function wcj_change_price_shipping_package_rates( $package_rates, $multiplier ) {
|
||||
$modified_package_rates = array();
|
||||
foreach ( $package_rates as $id => $package_rate ) {
|
||||
if ( 1 != $multiplier && isset( $package_rate->cost ) ) {
|
||||
$package_rate->cost = $package_rate->cost * $multiplier;
|
||||
if ( isset( $package_rate->taxes ) && ! empty( $package_rate->taxes ) ) {
|
||||
if ( ! WCJ_IS_WC_VERSION_BELOW_3_2_0 ) {
|
||||
$rate_taxes = $package_rate->taxes;
|
||||
foreach ( $rate_taxes as &$tax ) {
|
||||
$tax *= $multiplier;
|
||||
}
|
||||
$package_rate->taxes = $rate_taxes;
|
||||
} else {
|
||||
foreach ( $package_rate->taxes as $tax_id => $tax ) {
|
||||
$package_rate->taxes[ $tax_id ] = $package_rate->taxes[ $tax_id ] * $multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$modified_package_rates[ $id ] = $package_rate;
|
||||
}
|
||||
return $modified_package_rates;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rate_product_base_currency' ) ) {
|
||||
/**
|
||||
* wcj_get_currency_exchange_rate_product_base_currency.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 2.5.6
|
||||
*/
|
||||
function wcj_get_currency_exchange_rate_product_base_currency( $currency_code ) {
|
||||
$total_number = apply_filters( 'booster_option', 1, get_option( 'wcj_multicurrency_base_price_total_number', 1 ) );
|
||||
for ( $i = 1; $i <= $total_number; $i++ ) {
|
||||
if ( $currency_code === get_option( 'wcj_multicurrency_base_price_currency_' . $i ) ) {
|
||||
return get_option( 'wcj_multicurrency_base_price_exchange_rate_' . $i );
|
||||
}
|
||||
}
|
||||
return 1; // fallback
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_price_by_product_base_currency' ) ) {
|
||||
/**
|
||||
* wcj_price_by_product_base_currency.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.5.6
|
||||
*/
|
||||
function wcj_price_by_product_base_currency( $price, $product_id ) {
|
||||
if ( '' == $price ) {
|
||||
return $price;
|
||||
}
|
||||
$do_save = ( 'yes' === get_option( 'wcj_multicurrency_base_price_save_prices', 'no' ) );
|
||||
if ( $do_save ) {
|
||||
$_current_filter = current_filter();
|
||||
if ( '' == $_current_filter ) {
|
||||
$_current_filter = 'wcj_filter__none';
|
||||
}
|
||||
}
|
||||
if ( $do_save && isset( WCJ()->modules['multicurrency_base_price']->calculated_products_prices[ $product_id ][ $_current_filter ] ) ) {
|
||||
return WCJ()->modules['multicurrency_base_price']->calculated_products_prices[ $product_id ][ $_current_filter ];
|
||||
}
|
||||
$multicurrency_base_price_currency = get_post_meta( $product_id, '_' . 'wcj_multicurrency_base_price_currency', true );
|
||||
if ( '' != $multicurrency_base_price_currency ) {
|
||||
if ( 1 != ( $currency_exchange_rate = wcj_get_currency_exchange_rate_product_base_currency( $multicurrency_base_price_currency ) ) && 0 != $currency_exchange_rate ) {
|
||||
$_price = $price / $currency_exchange_rate;
|
||||
if ( 'yes' === get_option( 'wcj_multicurrency_base_price_round_enabled', 'no' ) ) {
|
||||
$_price = round( $_price, get_option( 'wcj_multicurrency_base_price_round_precision', get_option( 'woocommerce_price_num_decimals' ) ) );
|
||||
}
|
||||
if ( $do_save ) {
|
||||
WCJ()->modules['multicurrency_base_price']->calculated_products_prices[ $product_id ][ $_current_filter ] = $_price;
|
||||
}
|
||||
return $_price;
|
||||
}
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_price_by_country' ) ) {
|
||||
/**
|
||||
* wcj_price_by_country.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_price_by_country( $price, $product, $group_id, $the_current_filter = '' ) {
|
||||
|
||||
$is_price_modified = false;
|
||||
|
||||
if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled', 'yes' ) ) {
|
||||
// Per product
|
||||
$meta_box_id = 'price_by_country';
|
||||
$scope = 'local';
|
||||
|
||||
if ( is_numeric( $product ) ) {
|
||||
$the_product_id = $product;
|
||||
} else {
|
||||
$the_product_id = wcj_get_product_id( $product );
|
||||
}
|
||||
|
||||
$the_product_id = wcj_maybe_get_product_id_wpml( $the_product_id );
|
||||
|
||||
$meta_id = '_' . 'wcj_' . $meta_box_id . '_make_empty_price_' . $scope . '_' . $group_id;
|
||||
if ( 'on' === get_post_meta( $the_product_id, $meta_id, true ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$price_by_country = '';
|
||||
if ( '' == $the_current_filter ) {
|
||||
$the_current_filter = current_filter();
|
||||
}
|
||||
if ( 'woocommerce_get_price_including_tax' == $the_current_filter || 'woocommerce_get_price_excluding_tax' == $the_current_filter ) {
|
||||
$_product = wc_get_product( $the_product_id );
|
||||
return wcj_get_product_display_price( $_product );
|
||||
|
||||
} elseif ( WCJ_PRODUCT_GET_PRICE_FILTER == $the_current_filter || 'woocommerce_variation_prices_price' == $the_current_filter || 'woocommerce_product_variation_get_price' == $the_current_filter ) {
|
||||
|
||||
$regular_or_sale = '_regular_price_';
|
||||
$meta_id = '_' . 'wcj_' . $meta_box_id . $regular_or_sale . $scope . '_' . $group_id;
|
||||
$regular_price = get_post_meta( $the_product_id, $meta_id, true );
|
||||
|
||||
$regular_or_sale = '_sale_price_';
|
||||
$meta_id = '_' . 'wcj_' . $meta_box_id . $regular_or_sale . $scope . '_' . $group_id;
|
||||
$sale_price = get_post_meta( $the_product_id, $meta_id, true );
|
||||
|
||||
if ( ! empty( $sale_price ) && $sale_price < $regular_price ) {
|
||||
$price_by_country = $sale_price;
|
||||
} else {
|
||||
$price_by_country = $regular_price;
|
||||
}
|
||||
|
||||
} elseif (
|
||||
WCJ_PRODUCT_GET_REGULAR_PRICE_FILTER == $the_current_filter ||
|
||||
WCJ_PRODUCT_GET_SALE_PRICE_FILTER == $the_current_filter ||
|
||||
'woocommerce_variation_prices_regular_price' == $the_current_filter ||
|
||||
'woocommerce_variation_prices_sale_price' == $the_current_filter ||
|
||||
'woocommerce_product_variation_get_regular_price' == $the_current_filter ||
|
||||
'woocommerce_product_variation_get_sale_price' == $the_current_filter
|
||||
) {
|
||||
$regular_or_sale = (
|
||||
WCJ_PRODUCT_GET_REGULAR_PRICE_FILTER == $the_current_filter || 'woocommerce_variation_prices_regular_price' == $the_current_filter || 'woocommerce_product_variation_get_regular_price' == $the_current_filter
|
||||
) ? '_regular_price_' : '_sale_price_';
|
||||
$meta_id = '_' . 'wcj_' . $meta_box_id . $regular_or_sale . $scope . '_' . $group_id;
|
||||
$price_by_country = get_post_meta( $the_product_id, $meta_id, true );
|
||||
}
|
||||
|
||||
if ( '' != $price_by_country ) {
|
||||
$modified_price = $price_by_country;
|
||||
$is_price_modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $is_price_modified ) {
|
||||
if ( 'yes' === get_option( 'wcj_price_by_country_make_empty_price_group_' . $group_id, 1 ) || '' === $price ) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $is_price_modified ) {
|
||||
// Globally
|
||||
$country_exchange_rate = get_option( 'wcj_price_by_country_exchange_rate_group_' . $group_id, 1 );
|
||||
// if ( 1 != $country_exchange_rate ) {
|
||||
$modified_price = $price * $country_exchange_rate;
|
||||
$rounding = get_option( 'wcj_price_by_country_rounding', 'none' );
|
||||
$precision = get_option( 'woocommerce_price_num_decimals', 2 );
|
||||
switch ( $rounding ) {
|
||||
case 'round':
|
||||
$modified_price = round( $modified_price );
|
||||
break;
|
||||
case 'floor':
|
||||
$modified_price = floor( $modified_price );
|
||||
break;
|
||||
case 'ceil':
|
||||
$modified_price = ceil( $modified_price );
|
||||
break;
|
||||
default: // case 'none':
|
||||
$modified_price = round( $modified_price, $precision ); // $modified_price
|
||||
break;
|
||||
}
|
||||
$is_price_modified = true;
|
||||
// }
|
||||
if ( 'yes' === get_option( 'wcj_price_by_country_make_pretty', 'no' ) && $modified_price >= 0.5 && $precision > 0 ) {
|
||||
$modified_price = round( $modified_price ) - ( get_option( 'wcj_price_by_country_make_pretty_min_amount_multiplier', 1 ) / pow( 10, $precision ) );
|
||||
}
|
||||
}
|
||||
|
||||
return ( $is_price_modified ) ? $modified_price : $price;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_update_products_price_by_country_for_single_product' ) ) {
|
||||
/**
|
||||
* wcj_update_products_price_by_country_for_single_product.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_update_products_price_by_country_for_single_product( $product_id ) {
|
||||
$_product = wc_get_product( $product_id );
|
||||
if ( $_product->is_type( 'variable' ) ) {
|
||||
$available_variations = $_product->get_available_variations();
|
||||
for ( $i = 1; $i <= apply_filters( 'booster_option', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
|
||||
$min_variation_price = PHP_INT_MAX;
|
||||
$max_variation_price = 0;
|
||||
foreach ( $available_variations as $variation ) {
|
||||
$variation_product_id = $variation['variation_id'];
|
||||
$_old_variation_price = get_post_meta( $variation_product_id, '_price', true );
|
||||
if ( wcj_is_module_enabled( 'multicurrency_base_price' ) ) {
|
||||
$_old_variation_price = wcj_price_by_product_base_currency( $_old_variation_price, $product_id );
|
||||
}
|
||||
$price_by_country = wcj_price_by_country( $_old_variation_price, $variation_product_id, $i, WCJ_PRODUCT_GET_PRICE_FILTER );
|
||||
update_post_meta( $variation_product_id, '_' . 'wcj_price_by_country_' . $i, $price_by_country );
|
||||
if ( '' != $price_by_country && $price_by_country < $min_variation_price ) {
|
||||
$min_variation_price = $price_by_country;
|
||||
}
|
||||
if ( $price_by_country > $max_variation_price ) {
|
||||
$max_variation_price = $price_by_country;
|
||||
}
|
||||
}
|
||||
delete_post_meta( $product_id, '_' . 'wcj_price_by_country_' . $i );
|
||||
add_post_meta( $product_id, '_' . 'wcj_price_by_country_' . $i, $min_variation_price );
|
||||
if ( $min_variation_price != $max_variation_price ) {
|
||||
add_post_meta( $product_id, '_' . 'wcj_price_by_country_' . $i, $max_variation_price );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$_old_price = get_post_meta( $product_id, '_price', true );
|
||||
if ( wcj_is_module_enabled( 'multicurrency_base_price' ) ) {
|
||||
$_old_price = wcj_price_by_product_base_currency( $_old_price, $product_id );
|
||||
}
|
||||
for ( $i = 1; $i <= apply_filters( 'booster_option', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
|
||||
$price_by_country = wcj_price_by_country( $_old_price, $product_id, $i, WCJ_PRODUCT_GET_PRICE_FILTER );
|
||||
update_post_meta( $product_id, '_' . 'wcj_price_by_country_' . $i, $price_by_country );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_update_products_price_by_country' ) ) {
|
||||
/**
|
||||
* wcj_update_products_price_by_country - all products.
|
||||
*
|
||||
* @version 2.5.3
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_update_products_price_by_country() {
|
||||
$offset = 0;
|
||||
$block_size = 96;
|
||||
while( true ) {
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => $block_size,
|
||||
'offset' => $offset,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
if ( ! $loop->have_posts() ) break;
|
||||
while ( $loop->have_posts() ) : $loop->the_post();
|
||||
$product_id = $loop->post->ID;
|
||||
wcj_update_products_price_by_country_for_single_product( $product_id );
|
||||
endwhile;
|
||||
$offset += $block_size;
|
||||
}
|
||||
wp_reset_postdata();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_current_currency_code' ) ) {
|
||||
/**
|
||||
* wcj_get_current_currency_code.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function wcj_get_current_currency_code( $module ) {
|
||||
$current_currency_code = get_woocommerce_currency();
|
||||
if ( wcj_is_module_enabled( $module ) ) {
|
||||
if ( 'multicurrency' === $module ) {
|
||||
$current_currency_code = ( null !== ( $session_value = wcj_session_get( 'wcj-currency' ) ) ? $session_value : $current_currency_code );
|
||||
}
|
||||
}
|
||||
return $current_currency_code;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_by_country' ) ) {
|
||||
/**
|
||||
* wcj_get_currency_by_country.
|
||||
*
|
||||
* @version 2.5.4
|
||||
* @since 2.5.4
|
||||
*/
|
||||
function wcj_get_currency_by_country( $country_code ) {
|
||||
$currency_code = '';
|
||||
for ( $i = 1; $i <= apply_filters( 'booster_option', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
|
||||
switch ( get_option( 'wcj_price_by_country_selection', 'comma_list' ) ) {
|
||||
case 'comma_list':
|
||||
$country_exchange_rate_group = get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
|
||||
$country_exchange_rate_group = str_replace( ' ', '', $country_exchange_rate_group );
|
||||
$country_exchange_rate_group = explode( ',', $country_exchange_rate_group );
|
||||
break;
|
||||
case 'multiselect':
|
||||
$country_exchange_rate_group = get_option( 'wcj_price_by_country_countries_group_' . $i );
|
||||
break;
|
||||
case 'chosen_select':
|
||||
$country_exchange_rate_group = get_option( 'wcj_price_by_country_countries_group_chosen_select_' . $i );
|
||||
break;
|
||||
}
|
||||
if ( in_array( $country_code, $country_exchange_rate_group ) ) {
|
||||
$currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ( '' == $currency_code ) ? get_option( 'woocommerce_currency' ) : $currency_code;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_exchange_rate' ) ) {
|
||||
/**
|
||||
* wcj_get_currency_exchange_rate.
|
||||
*
|
||||
* @version 2.5.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function wcj_get_currency_exchange_rate( $module, $currency_code ) {
|
||||
$currency_exchange_rate = 1;
|
||||
if ( wcj_is_module_enabled( $module ) ) {
|
||||
if ( 'multicurrency' === $module ) {
|
||||
$total_number = apply_filters( 'booster_option', 2, get_option( 'wcj_multicurrency_total_number', 2 ) );
|
||||
for ( $i = 1; $i <= $total_number; $i++ ) {
|
||||
if ( $currency_code === get_option( 'wcj_multicurrency_currency_' . $i ) ) {
|
||||
$currency_exchange_rate = get_option( 'wcj_multicurrency_exchange_rate_' . $i );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $currency_exchange_rate;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wc_get_product_purchase_price' ) ) {
|
||||
/**
|
||||
* wc_get_product_purchase_price.
|
||||
*
|
||||
* @version 3.2.4
|
||||
*/
|
||||
function wc_get_product_purchase_price( $product_id = 0 ) {
|
||||
if ( 0 == $product_id ) {
|
||||
$product_id = get_the_ID();
|
||||
}
|
||||
$purchase_price = 0;
|
||||
if ( 'yes' === get_option( 'wcj_purchase_price_enabled', 'yes' ) ) {
|
||||
$purchase_price += (float) get_post_meta( $product_id, '_' . 'wcj_purchase_price' , true );
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_purchase_price_extra_enabled', 'yes' ) ) {
|
||||
$purchase_price += (float) get_post_meta( $product_id, '_' . 'wcj_purchase_price_extra', true );
|
||||
}
|
||||
if ( 'yes' === get_option( 'wcj_purchase_price_affiliate_commission_enabled', 'no' ) ) {
|
||||
$purchase_price += (float) get_post_meta( $product_id, '_' . 'wcj_purchase_price_affiliate_commission', true );
|
||||
}
|
||||
$total_number = apply_filters( 'booster_option', 1, get_option( 'wcj_purchase_data_custom_price_fields_total_number', 1 ) );
|
||||
for ( $i = 1; $i <= $total_number; $i++ ) {
|
||||
if ( '' == get_option( 'wcj_purchase_data_custom_price_field_name_' . $i, '' ) ) {
|
||||
continue;
|
||||
}
|
||||
$meta_value = (float) get_post_meta( $product_id, '_' . 'wcj_purchase_price_custom_field_' . $i, true );
|
||||
if ( 0 != $meta_value ) {
|
||||
$purchase_price += ( 'fixed' === get_option( 'wcj_purchase_data_custom_price_field_type_' . $i, 'fixed' ) ) ? $meta_value : $purchase_price * $meta_value / 100.0;
|
||||
}
|
||||
}
|
||||
return apply_filters( 'wcj_get_product_purchase_price', $purchase_price, $product_id );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currencies_names_and_symbols' ) ) {
|
||||
/**
|
||||
* wcj_get_currencies_names_and_symbols.
|
||||
*
|
||||
* @version 2.4.4
|
||||
*/
|
||||
function wcj_get_currencies_names_and_symbols( $result = 'names_and_symbols', $scope = 'all' ) {
|
||||
$currency_names_and_symbols = array();
|
||||
/* if ( ! wcj_is_module_enabled( 'currency' ) ) {
|
||||
return $currency_names_and_symbols;
|
||||
} */
|
||||
if ( 'all' === $scope || 'no_custom' === $scope ) {
|
||||
$currencies = wcj_get_currencies_array();
|
||||
foreach( $currencies as $data ) {
|
||||
switch ( $result ) {
|
||||
case 'names_and_symbols':
|
||||
$currency_names_and_symbols[ $data['code'] ] = $data['name'] . ' (' . $data['symbol'] . ')';
|
||||
break;
|
||||
case 'names':
|
||||
$currency_names_and_symbols[ $data['code'] ] = $data['name'];
|
||||
break;
|
||||
case 'symbols':
|
||||
$currency_names_and_symbols[ $data['code'] ] = $data['symbol'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( wcj_is_module_enabled( 'currency' ) && ( 'all' === $scope || 'custom_only' === $scope ) ) {
|
||||
// Custom currencies
|
||||
$custom_currency_total_number = apply_filters( 'booster_option', 1, get_option( 'wcj_currency_custom_currency_total_number', 1 ) );
|
||||
for ( $i = 1; $i <= $custom_currency_total_number; $i++) {
|
||||
$custom_currency_code = get_option( 'wcj_currency_custom_currency_code_' . $i );
|
||||
$custom_currency_name = get_option( 'wcj_currency_custom_currency_name_' . $i );
|
||||
$custom_currency_symbol = get_option( 'wcj_currency_custom_currency_symbol_' . $i );
|
||||
if ( '' != $custom_currency_code && '' != $custom_currency_name /* && '' != $custom_currency_symbol */ ) {
|
||||
switch ( $result ) {
|
||||
case 'names_and_symbols':
|
||||
$currency_names_and_symbols[ $custom_currency_code ] = $custom_currency_name . ' (' . $custom_currency_symbol . ')';
|
||||
break;
|
||||
case 'names':
|
||||
$currency_names_and_symbols[ $custom_currency_code ] = $custom_currency_name;
|
||||
break;
|
||||
case 'symbols':
|
||||
$currency_names_and_symbols[ $custom_currency_code ] = $custom_currency_symbol;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $currency_names_and_symbols;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_currency_symbol' ) ) {
|
||||
/**
|
||||
* wcj_get_currency_symbol.
|
||||
*
|
||||
* @version 2.4.4
|
||||
*/
|
||||
function wcj_get_currency_symbol( $currency_code ) {
|
||||
$return = '';
|
||||
$currencies = wcj_get_currencies_names_and_symbols( 'symbols', 'no_custom' );
|
||||
if ( isset( $currencies[ $currency_code ] ) ) {
|
||||
if ( wcj_is_module_enabled( 'currency' ) ) {
|
||||
$return = apply_filters( 'booster_option', $currencies[ $currency_code ], get_option( 'wcj_currency_' . $currency_code, $currencies[ $currency_code ] ) );
|
||||
} else {
|
||||
$return = $currencies[ $currency_code ];
|
||||
}
|
||||
} else {
|
||||
$currencies = wcj_get_currencies_names_and_symbols( 'symbols', 'custom_only' );
|
||||
$return = isset( $currencies[ $currency_code ] ) ? $currencies[ $currency_code ] : '';
|
||||
}
|
||||
return ( '' != $return ) ? $return : false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_price' ) ) {
|
||||
/**
|
||||
* wcj_price.
|
||||
*/
|
||||
function wcj_price( $price, $currency, $hide_currency ) {
|
||||
return ( 'yes' === $hide_currency ) ? wc_price( $price, array( 'currency' => 'DISABLED' ) ) : wc_price( $price, array( 'currency' => $currency ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Products
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_maybe_get_product_id_wpml' ) ) {
|
||||
/**
|
||||
* wcj_maybe_get_product_id_wpml.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 3.6.0
|
||||
*/
|
||||
function wcj_maybe_get_product_id_wpml( $product_id ) {
|
||||
if ( function_exists( 'icl_object_id' ) ) {
|
||||
$product_id = icl_object_id( $product_id, 'product', true, wcj_get_wpml_default_language() );
|
||||
}
|
||||
return $product_id;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_enabled_for_product' ) ) {
|
||||
/*
|
||||
* wcj_is_enabled_for_product.
|
||||
*
|
||||
* @version 3.1.0
|
||||
* @since 3.1.0
|
||||
*/
|
||||
function wcj_is_enabled_for_product( $product_id, $args ) {
|
||||
if ( isset( $args['include_products'] ) && ! empty( $args['include_products'] ) ) {
|
||||
if ( ! is_array( $args['include_products'] ) ) {
|
||||
$args['include_products'] = array_map( 'trim', explode( ',', $args['include_products'] ) );
|
||||
}
|
||||
if ( ! in_array( $product_id, $args['include_products'] ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $args['exclude_products'] ) && ! empty( $args['exclude_products'] ) ) {
|
||||
if ( ! is_array( $args['exclude_products'] ) ) {
|
||||
$args['exclude_products'] = array_map( 'trim', explode( ',', $args['exclude_products'] ) );
|
||||
}
|
||||
if ( in_array( $product_id, $args['exclude_products'] ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $args['include_categories'] ) && ! empty( $args['include_categories'] ) ) {
|
||||
if ( ! wcj_is_product_term( $product_id, $args['include_categories'], 'product_cat' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $args['exclude_categories'] ) && ! empty( $args['exclude_categories'] ) ) {
|
||||
if ( wcj_is_product_term( $product_id, $args['exclude_categories'], 'product_cat' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $args['include_tags'] ) && ! empty( $args['include_tags'] ) ) {
|
||||
if ( ! wcj_is_product_term( $product_id, $args['include_tags'], 'product_tag' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( isset( $args['exclude_tags'] ) && ! empty( $args['exclude_tags'] ) ) {
|
||||
if ( wcj_is_product_term( $product_id, $args['exclude_tags'], 'product_tag' ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_id' ) ) {
|
||||
/**
|
||||
* wcj_get_product_id.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_product_id( $_product ) {
|
||||
if ( ! $_product || ! is_object( $_product ) ) {
|
||||
return 0;
|
||||
}
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
return ( isset( $_product->variation_id ) ) ? $_product->variation_id : $_product->id;
|
||||
} else {
|
||||
return $_product->get_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_id_or_variation_parent_id' ) ) {
|
||||
/**
|
||||
* wcj_get_product_id_or_variation_parent_id.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_product_id_or_variation_parent_id( $_product ) {
|
||||
if ( ! $_product || ! is_object( $_product ) ) {
|
||||
return 0;
|
||||
}
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
return $_product->id;
|
||||
} else {
|
||||
return ( $_product->is_type( 'variation' ) ) ? $_product->get_parent_id() : $_product->get_id();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_status' ) ) {
|
||||
/**
|
||||
* wcj_get_product_status.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_product_status( $_product ) {
|
||||
return ( WCJ_IS_WC_VERSION_BELOW_3 ) ? $_product->post->post_status : $_product->get_status();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_total_stock' ) ) {
|
||||
/**
|
||||
* wcj_get_product_total_stock.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_product_total_stock( $_product ) {
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
return $_product->get_total_stock();
|
||||
} else {
|
||||
if ( $_product->is_type( array( 'variable', 'grouped' ) ) ) {
|
||||
$total_stock = 0;
|
||||
foreach ( $_product->get_children() as $child_id ) {
|
||||
$child = wc_get_product( $child_id );
|
||||
$total_stock += $child->get_stock_quantity();
|
||||
}
|
||||
return $total_stock;
|
||||
} else {
|
||||
return $_product->get_stock_quantity();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_display_price' ) ) {
|
||||
/**
|
||||
* wcj_get_product_display_price.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.7.0
|
||||
* @todo `$scope` in `WCJ_IS_WC_VERSION_BELOW_3` (i.e. `cart`)
|
||||
*/
|
||||
function wcj_get_product_display_price( $_product, $price = '', $qty = 1, $scope = 'shop' ) {
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
return $_product->get_display_price( $price, $qty );
|
||||
} else {
|
||||
$minus_sign = '';
|
||||
if ( $price < 0 ) {
|
||||
$minus_sign = '-';
|
||||
$price *= -1;
|
||||
}
|
||||
if ( 'cart' === $scope ) {
|
||||
$display_price = ( 'incl' === get_option( 'woocommerce_tax_display_cart' ) ?
|
||||
wc_get_price_including_tax( $_product, array( 'price' => $price, 'qty' => $qty ) ) :
|
||||
wc_get_price_excluding_tax( $_product, array( 'price' => $price, 'qty' => $qty ) ) );
|
||||
} else { // 'shop'
|
||||
$display_price = wc_get_price_to_display( $_product, array( 'price' => $price, 'qty' => $qty ) );
|
||||
}
|
||||
return $minus_sign . $display_price;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_formatted_variation' ) ) {
|
||||
/**
|
||||
* wcj_get_product_formatted_variation.
|
||||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
function wcj_get_product_formatted_variation( $variation, $flat = false, $include_names = true ) {
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
return $variation->get_formatted_variation_attributes( $flat );
|
||||
} else {
|
||||
return wc_get_formatted_variation( $variation, $flat, $include_names );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_image_url' ) ) {
|
||||
/**
|
||||
* wcj_get_product_image_url.
|
||||
*
|
||||
* @version 2.5.7
|
||||
* @since 2.5.7
|
||||
* @todo placeholder
|
||||
*/
|
||||
function wcj_get_product_image_url( $product_id, $image_size = 'shop_thumbnail' ) {
|
||||
if ( has_post_thumbnail( $product_id ) ) {
|
||||
$image_url = get_the_post_thumbnail_url( $product_id, $image_size );
|
||||
} elseif ( ( $parent_id = wp_get_post_parent_id( $product_id ) ) && has_post_thumbnail( $parent_id ) ) {
|
||||
$image_url = get_the_post_thumbnail_url( $parent_id, $image_size );
|
||||
} else {
|
||||
$image_url = '';
|
||||
}
|
||||
return $image_url;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_input_field_value' ) ) {
|
||||
/**
|
||||
* wcj_get_product_input_field_value.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 3.5.1
|
||||
*/
|
||||
function wcj_get_product_input_field_value( $item, $key, $field ) {
|
||||
$key = explode( '_', str_replace( '_wcj_product_input_fields_', '', $key ) );
|
||||
$scope = $key[0];
|
||||
$option_name = 'wcj_product_input_fields_' . $field . '_' . $scope . '_' . $key[1];
|
||||
$product_id = $item['product_id'];
|
||||
$default = '';
|
||||
if ( 'global' === $scope ) {
|
||||
return get_option( $option_name, $default );
|
||||
} else { // local
|
||||
if ( '' != ( $options = get_post_meta( $product_id, '_' . 'wcj_product_input_fields', true ) ) ) {
|
||||
$option_name = str_replace( 'wcj_product_input_fields_', '', $option_name );
|
||||
return ( isset( $options[ $option_name ] ) ? $options[ $option_name ] : $default );
|
||||
} else { // Booster version < 3.5.0
|
||||
return get_post_meta( $product_id, '_' . $option_name, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_input_fields' ) ) {
|
||||
/*
|
||||
* wcj_get_product_input_fields.
|
||||
*
|
||||
* @version 3.5.1
|
||||
* @since 2.4.4
|
||||
* @return string
|
||||
* @todo (maybe) better handle "file" type
|
||||
*/
|
||||
function wcj_get_product_input_fields( $item, $do_add_titles = false, $sep = ', ' ) {
|
||||
$product_input_fields = array();
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
foreach ( $item as $key => $value ) {
|
||||
if ( false !== strpos( $key, 'wcj_product_input_fields_' ) ) {
|
||||
$title = ( $do_add_titles ? wcj_get_product_input_field_value( $item, $key, 'title' ) . ': ' : '' );
|
||||
$product_input_fields[] = $title . wcj_maybe_unserialize_and_implode( $value );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ( $item->get_meta_data() as $value ) {
|
||||
if ( isset( $value->key ) && isset( $value->value ) && false !== strpos( $value->key, 'wcj_product_input_fields_' ) ) {
|
||||
$title = ( $do_add_titles ? wcj_get_product_input_field_value( $item, $value->key, 'title' ) . ': ' : '' );
|
||||
$product_input_fields[] = $title . wcj_maybe_unserialize_and_implode( $value->value );
|
||||
}
|
||||
}
|
||||
}
|
||||
return ( ! empty( $product_input_fields ) ) ? implode( $sep, array_map( 'wcj_maybe_implode', $product_input_fields ) ) : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_index_from_key' ) ) {
|
||||
/*
|
||||
* wcj_get_index_from_key.
|
||||
*
|
||||
* @version 3.0.0
|
||||
* @since 3.0.0
|
||||
* @return string
|
||||
*/
|
||||
function wcj_get_index_from_key( $key ) {
|
||||
$index = explode( '_', $key );
|
||||
$index = array_reverse( $index );
|
||||
return $index[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_addons' ) ) {
|
||||
/*
|
||||
* wcj_get_product_addons.
|
||||
*
|
||||
* @version 3.0.0
|
||||
* @since 3.0.0
|
||||
* @return string
|
||||
*/
|
||||
function wcj_get_product_addons( $item, $order_currency ) {
|
||||
|
||||
// Prepare item values
|
||||
$values = array();
|
||||
if ( WCJ_IS_WC_VERSION_BELOW_3 ) {
|
||||
$values = $item;
|
||||
} else {
|
||||
foreach ( $item->get_meta_data() as $value ) {
|
||||
if ( isset( $value->key ) && isset( $value->value ) ) {
|
||||
$values[ $value->key ] = $value->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare addons (if any)
|
||||
$addons = array();
|
||||
foreach ( $values as $key => $value ) {
|
||||
if ( false !== strpos( $key, 'wcj_product_all_products_addons_label_' ) ) {
|
||||
$addons['all_products'][ wcj_get_index_from_key( $key ) ]['label'] = $value;
|
||||
}
|
||||
if ( false !== strpos( $key, 'wcj_product_per_product_addons_label_' ) ) {
|
||||
$addons['per_product'][ wcj_get_index_from_key( $key ) ]['label'] = $value;
|
||||
}
|
||||
if ( false !== strpos( $key, 'wcj_product_all_products_addons_price_' ) ) {
|
||||
$addons['all_products'][ wcj_get_index_from_key( $key ) ]['price'] = $value;
|
||||
}
|
||||
if ( false !== strpos( $key, 'wcj_product_per_product_addons_price_' ) ) {
|
||||
$addons['per_product'][ wcj_get_index_from_key( $key ) ]['price'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Final result array
|
||||
$return = array();
|
||||
foreach ( $addons as $scope => $scope_addons ) {
|
||||
foreach ( $scope_addons as $index => $addons_data ) {
|
||||
$return[] = $addons_data['label'] . ': ' . wc_price( $addons_data['price'], array( 'currency' => $order_currency ) );
|
||||
}
|
||||
}
|
||||
return ( ! empty( $return ) ) ? implode( ', ', $return ) : '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_products' ) ) {
|
||||
/**
|
||||
* wcj_get_products.
|
||||
*
|
||||
* @version 3.5.0
|
||||
*/
|
||||
function wcj_get_products( $products = array(), $post_status = 'any', $block_size = 256, $add_variations = false ) {
|
||||
$offset = 0;
|
||||
while( true ) {
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => $post_status,
|
||||
'posts_per_page' => $block_size,
|
||||
'offset' => $offset,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'fields' => 'ids',
|
||||
);
|
||||
$loop = new WP_Query( $args );
|
||||
if ( ! $loop->have_posts() ) {
|
||||
break;
|
||||
}
|
||||
foreach ( $loop->posts as $post_id ) {
|
||||
$products[ $post_id ] = get_the_title( $post_id ) . ' (ID:' . $post_id . ')';
|
||||
if ( $add_variations ) {
|
||||
$_product = wc_get_product( $post_id );
|
||||
if ( $_product->is_type( 'variable' ) ) {
|
||||
foreach ( $_product->get_children() as $child_id ) {
|
||||
$products[ $child_id ] = get_the_title( $child_id ) . ' (ID:' . $child_id . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$offset += $block_size;
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_product_has_terms' ) ) {
|
||||
/**
|
||||
* wcj_product_has_terms.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 2.8.2
|
||||
*/
|
||||
function wcj_product_has_terms( $_product, $_values, $_term ) {
|
||||
if ( is_string( $_values ) ) {
|
||||
$_values = explode( ',', $_values );
|
||||
}
|
||||
if ( empty( $_values ) ) {
|
||||
return false;
|
||||
}
|
||||
$product_id = ( is_numeric( $_product ) && $_product > 0 ? $_product : wcj_get_product_id_or_variation_parent_id( $_product ) );
|
||||
$product_categories = get_the_terms( $product_id, $_term );
|
||||
if ( empty( $product_categories ) ) {
|
||||
return false;
|
||||
}
|
||||
foreach ( $product_categories as $product_category ) {
|
||||
foreach ( $_values as $_value ) {
|
||||
if ( $product_category->slug === $_value ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_product_wholesale_enabled_per_product' ) ) {
|
||||
/**
|
||||
* wcj_is_product_wholesale_enabled_per_product.
|
||||
*
|
||||
* @version 3.3.0
|
||||
* @since 2.5.0
|
||||
*/
|
||||
function wcj_is_product_wholesale_enabled_per_product( $product_id ) {
|
||||
return (
|
||||
'yes' === get_option( 'wcj_wholesale_price_per_product_enable', 'yes' ) &&
|
||||
'yes' === get_post_meta( $product_id, '_' . 'wcj_wholesale_price_per_product_enabled', true )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_product_wholesale_enabled' ) ) {
|
||||
/**
|
||||
* wcj_is_product_wholesale_enabled.
|
||||
*
|
||||
* @version 3.7.0
|
||||
*/
|
||||
function wcj_is_product_wholesale_enabled( $product_id ) {
|
||||
if ( wcj_is_module_enabled( 'wholesale_price' ) ) {
|
||||
if ( wcj_is_product_wholesale_enabled_per_product( $product_id ) ) {
|
||||
return true;
|
||||
} else {
|
||||
$products_to_include_passed = false;
|
||||
$products_to_include = get_option( 'wcj_wholesale_price_products_to_include', array() );
|
||||
if ( empty( $products_to_include ) || in_array( $product_id, $products_to_include ) ) {
|
||||
$products_to_include_passed = true;
|
||||
}
|
||||
$products_to_exclude_passed = false;
|
||||
$products_to_exclude = get_option( 'wcj_wholesale_price_products_to_exclude', array() );
|
||||
if ( empty( $products_to_exclude ) || ! in_array( $product_id, $products_to_exclude ) ) {
|
||||
$products_to_exclude_passed = true;
|
||||
}
|
||||
$product_cats_to_include_passed = false;
|
||||
$product_cats_to_include = get_option( 'wcj_wholesale_price_product_cats_to_include', array() );
|
||||
if ( empty( $product_cats_to_include ) || wcj_is_product_term( $product_id, $product_cats_to_include, 'product_cat' ) ) {
|
||||
$product_cats_to_include_passed = true;
|
||||
}
|
||||
$product_cats_to_exclude_passed = false;
|
||||
$product_cats_to_exclude = get_option( 'wcj_wholesale_price_product_cats_to_exclude', array() );
|
||||
if ( empty( $product_cats_to_exclude ) || ! wcj_is_product_term( $product_id, $product_cats_to_exclude, 'product_cat' ) ) {
|
||||
$product_cats_to_exclude_passed = true;
|
||||
}
|
||||
return ( $products_to_include_passed && $products_to_exclude_passed && $product_cats_to_include_passed && $product_cats_to_exclude_passed );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_the_terms' ) ) {
|
||||
/**
|
||||
* wcj_get_the_terms.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @version 2.9.0
|
||||
*/
|
||||
function wcj_get_the_terms( $product_id, $taxonomy ) {
|
||||
$result = array();
|
||||
$_terms = get_the_terms( $product_id, $taxonomy );
|
||||
if ( ! empty( $_terms ) ) {
|
||||
foreach( $_terms as $_term ) {
|
||||
$result[] = $_term->term_id;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_product_term' ) ) {
|
||||
/**
|
||||
* wcj_is_product_term.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_is_product_term( $product_id, $term_ids, $taxonomy ) {
|
||||
if ( empty( $term_ids ) ) {
|
||||
return false;
|
||||
}
|
||||
$product_terms = get_the_terms( $product_id, $taxonomy );
|
||||
if ( empty( $product_terms ) ) {
|
||||
return false;
|
||||
}
|
||||
foreach( $product_terms as $product_term ) {
|
||||
if ( in_array( $product_term->term_id, $term_ids ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_terms' ) ) {
|
||||
/**
|
||||
* wcj_get_terms.
|
||||
*
|
||||
* @version 2.8.0
|
||||
* @since 2.8.0
|
||||
*/
|
||||
function wcj_get_terms( $args ) {
|
||||
if ( ! is_array( $args ) ) {
|
||||
$_taxonomy = $args;
|
||||
$args = array(
|
||||
'taxonomy' => $_taxonomy,
|
||||
'orderby' => 'name',
|
||||
'hide_empty' => false,
|
||||
);
|
||||
}
|
||||
global $wp_version;
|
||||
if ( version_compare( $wp_version, '4.5.0', '>=' ) ) {
|
||||
$_terms = get_terms( $args );
|
||||
} else {
|
||||
$_taxonomy = $args['taxonomy'];
|
||||
unset( $args['taxonomy'] );
|
||||
$_terms = get_terms( $_taxonomy, $args );
|
||||
}
|
||||
$_terms_options = array();
|
||||
if ( ! empty( $_terms ) && ! is_wp_error( $_terms ) ){
|
||||
foreach ( $_terms as $_term ) {
|
||||
$_terms_options[ $_term->term_id ] = $_term->name;
|
||||
}
|
||||
}
|
||||
return $_terms_options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Reports
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 2.9.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_sales_daily_report_columns' ) ) {
|
||||
/*
|
||||
* wcj_get_product_sales_daily_report_columns.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_get_product_sales_daily_report_columns() {
|
||||
return array(
|
||||
'date' => __( 'Date', 'woocommerce-jetpack' ),
|
||||
'daily_total_sum' => __( 'Daily Total Sum', 'woocommerce-jetpack' ),
|
||||
'daily_total_quantity' => __( 'Daily Total Quantity', 'woocommerce-jetpack' ),
|
||||
'product_id' => __( 'Product ID', 'woocommerce-jetpack' ),
|
||||
'item_title' => __( 'Item Title', 'woocommerce-jetpack' ),
|
||||
'item_quantity' => __( 'Quantity', 'woocommerce-jetpack' ),
|
||||
'sum' => __( 'Sum', 'woocommerce-jetpack' ),
|
||||
'profit' => __( 'Profit', 'woocommerce-jetpack' ),
|
||||
'last_sale' => __( 'Last Sale Date', 'woocommerce-jetpack' ),
|
||||
'last_sale_order_id' => __( 'Last Sale Order ID', 'woocommerce-jetpack' ),
|
||||
'last_sale_order_status' => __( 'Last Sale Order Status', 'woocommerce-jetpack' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_reports_standard_ranges' ) ) {
|
||||
/*
|
||||
* wcj_get_reports_standard_ranges.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_get_reports_standard_ranges() {
|
||||
$current_time = (int) current_time( 'timestamp' );
|
||||
return array(
|
||||
'year' => array(
|
||||
'title' => __( 'Year', 'woocommerce' ),
|
||||
'start_date' => date( 'Y-01-01', $current_time ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_month' => array(
|
||||
'title' => __( 'Last month', 'woocommerce' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( 'first day of previous month', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', strtotime( 'last day of previous month', $current_time ) ),
|
||||
),
|
||||
'this_month' => array(
|
||||
'title' => __( 'This month', 'woocommerce' ),
|
||||
'start_date' => date( 'Y-m-01', $current_time ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_7_days' => array(
|
||||
'title' => __( 'Last 7 days', 'woocommerce' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-7 days', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_reports_custom_ranges' ) ) {
|
||||
/*
|
||||
* wcj_get_reports_custom_ranges.
|
||||
*
|
||||
* @version 3.2.4
|
||||
* @since 2.9.0
|
||||
* @todo fix `-1 month` - sometimes it produces the wrong result (e.g. on current date = "2018.03.30")
|
||||
*/
|
||||
function wcj_get_reports_custom_ranges() {
|
||||
$current_time = (int) current_time( 'timestamp' );
|
||||
return array(
|
||||
'last_14_days' => array(
|
||||
'title' => __( 'Last 14 days', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-14 days', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_30_days' => array(
|
||||
'title' => __( 'Last 30 days', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-30 days', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_3_months' => array(
|
||||
'title' => __( 'Last 3 months', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-3 months', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_6_months' => array(
|
||||
'title' => __( 'Last 6 months', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-6 months', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_12_months' => array(
|
||||
'title' => __( 'Last 12 months', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-12 months', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_24_months' => array(
|
||||
'title' => __( 'Last 24 months', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-24 months', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'last_36_months' => array(
|
||||
'title' => __( 'Last 36 months', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-36 months', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
'same_days_last_month' => array(
|
||||
'title' => __( 'Same days last month', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-01', strtotime( '-1 month', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', strtotime( '-1 month', $current_time ) ),
|
||||
),
|
||||
'same_days_last_year' => array(
|
||||
'title' => __( 'Same days last year', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-01', strtotime( '-1 year', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', strtotime( '-1 year', $current_time ) ),
|
||||
),
|
||||
'last_year' => array(
|
||||
'title' => __( 'Last year', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-01-01', strtotime( '-1 year', $current_time ) ),
|
||||
'end_date' => date( 'Y-12-31', strtotime( '-1 year', $current_time ) ),
|
||||
),
|
||||
'yesterday' => array(
|
||||
'title' => __( 'Yesterday', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( '-1 day', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', strtotime( '-1 day', $current_time ) ),
|
||||
),
|
||||
'today' => array(
|
||||
'title' => __( 'Today', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', $current_time ),
|
||||
'end_date' => date( 'Y-m-d', $current_time ),
|
||||
),
|
||||
/*
|
||||
'last_week' => array(
|
||||
'title' => __( 'Last week', 'woocommerce-jetpack' ),
|
||||
'start_date' => date( 'Y-m-d', strtotime( 'last monday', $current_time ) ),
|
||||
'end_date' => date( 'Y-m-d', strtotime( 'last sunday', $current_time ) ),
|
||||
),
|
||||
*/
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Shipping
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.5.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_shipping_time_table' ) ) {
|
||||
/**
|
||||
* wcj_get_shipping_time_table.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo customizable `$method_title` format
|
||||
* @todo predefined `$matching_zone_id` (i.e. `$atts['shipping_zone_id']`)
|
||||
* @todo all zones (i.e. no `$matching_zone_id`)
|
||||
* @todo customizable final message
|
||||
* @todo check for "Shipping Time" module to be enabled
|
||||
* @todo time in hours (i.e. not days)
|
||||
* @todo check for `WC()` etc. to exist
|
||||
*/
|
||||
function wcj_get_shipping_time_table( $do_use_shipping_instances, $option_id_shipping_class ) {
|
||||
$shipping_methods = ( $do_use_shipping_instances ? wcj_get_shipping_methods_instances( true ) : WC()->shipping()->load_shipping_methods() );
|
||||
$matching_zone_id = wcj_get_customer_shipping_matching_zone_id();
|
||||
$table_data = array();
|
||||
foreach ( $shipping_methods as $method ) {
|
||||
if ( $do_use_shipping_instances && $method['zone_id'] != $matching_zone_id ) {
|
||||
continue;
|
||||
}
|
||||
$option_id_shipping_method = ( $do_use_shipping_instances ? 'instance_' . $method['shipping_method_instance_id'] : $method->id );
|
||||
$option_id = 'wcj_shipping_time_' . $option_id_shipping_method . $option_id_shipping_class;
|
||||
if ( '' !== ( $time = get_option( $option_id, '' ) ) ) {
|
||||
$method_title = ( $do_use_shipping_instances ? $method['zone_name'] . ': ' . $method['shipping_method_title']: $method->get_method_title() );
|
||||
$table_data[] = array( $method_title, sprintf( __( '%s day(s)' ), $time ) );
|
||||
}
|
||||
}
|
||||
return ( empty( $table_data ) ? '' : wcj_get_table_html( $table_data, array( 'table_heading_type' => 'vertical' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_customer_shipping_matching_zone_id' ) ) {
|
||||
/**
|
||||
* wcj_get_customer_shipping_matching_zone_id.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo (maybe) move to `wcj-functions-users.php`
|
||||
* @todo (maybe) add `wcj_get_customer_shipping_destination()` function
|
||||
*/
|
||||
function wcj_get_customer_shipping_matching_zone_id() {
|
||||
$package = false;
|
||||
if ( is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
if ( '' != ( $meta = get_user_meta( $current_user->ID, 'shipping_country', true ) ) ) {
|
||||
$package['destination']['country'] = $meta;
|
||||
$package['destination']['state'] = get_user_meta( $current_user->ID, 'shipping_state', true );
|
||||
$package['destination']['postcode'] = '';
|
||||
}
|
||||
}
|
||||
if ( false === $package ) {
|
||||
$package['destination'] = wc_get_customer_default_location();
|
||||
$package['destination']['postcode'] = '';
|
||||
}
|
||||
$data_store = WC_Data_Store::load( 'shipping-zone' );
|
||||
return $data_store->get_zone_id_from_package( $package );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_product_shipping_class_term_id' ) ) {
|
||||
/**
|
||||
* wcj_get_product_shipping_class_term_id.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
* @todo (maybe) move to `wcj-functions-products.php`
|
||||
*/
|
||||
function wcj_get_product_shipping_class_term_id( $_product ) {
|
||||
$product_shipping_class = $_product->get_shipping_class();
|
||||
if ( '' != $product_shipping_class ) {
|
||||
foreach ( WC()->shipping->get_shipping_classes() as $shipping_class ) {
|
||||
if ( $product_shipping_class === $shipping_class->slug ) {
|
||||
return $shipping_class->term_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_shipping_classes' ) ) {
|
||||
/**
|
||||
* wcj_get_shipping_classes.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_get_shipping_classes( $include_empty_shipping_class = true ) {
|
||||
$shipping_classes = WC()->shipping->get_shipping_classes();
|
||||
$shipping_classes_data = array();
|
||||
foreach ( $shipping_classes as $shipping_class ) {
|
||||
$shipping_classes_data[ $shipping_class->term_id ] = $shipping_class->name;
|
||||
}
|
||||
if ( $include_empty_shipping_class ) {
|
||||
$shipping_classes_data[0] = __( 'No shipping class', 'woocommerce' );
|
||||
}
|
||||
return $shipping_classes_data;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_shipping_methods' ) ) {
|
||||
/**
|
||||
* wcj_get_shipping_methods.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_get_shipping_methods() {
|
||||
$shipping_methods = array();
|
||||
foreach ( WC()->shipping()->load_shipping_methods() as $method ) {
|
||||
$shipping_methods[ $method->id ] = $method->get_method_title();
|
||||
}
|
||||
return $shipping_methods;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_shipping_zones' ) ) {
|
||||
/**
|
||||
* wcj_get_shipping_zones.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_get_shipping_zones( $include_empty_zone = true ) {
|
||||
$zones = WC_Shipping_Zones::get_zones();
|
||||
if ( $include_empty_zone ) {
|
||||
$zone = new WC_Shipping_Zone( 0 );
|
||||
$zones[ $zone->get_id() ] = $zone->get_data();
|
||||
$zones[ $zone->get_id() ]['zone_id'] = $zone->get_id();
|
||||
$zones[ $zone->get_id() ]['formatted_zone_location'] = $zone->get_formatted_location();
|
||||
$zones[ $zone->get_id() ]['shipping_methods'] = $zone->get_shipping_methods();
|
||||
}
|
||||
return $zones;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_shipping_methods_instances' ) ) {
|
||||
/**
|
||||
* wcj_get_shipping_methods_instances.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_get_shipping_methods_instances( $full_data = false ) {
|
||||
$shipping_methods = array();
|
||||
foreach ( wcj_get_shipping_zones() as $zone_id => $zone_data ) {
|
||||
foreach ( $zone_data['shipping_methods'] as $shipping_method ) {
|
||||
if ( $full_data ) {
|
||||
$shipping_methods[ $shipping_method->instance_id ] = array(
|
||||
'zone_id' => $zone_id,
|
||||
'zone_name' => $zone_data['zone_name'],
|
||||
'formatted_zone_location' => $zone_data['formatted_zone_location'],
|
||||
'shipping_method_title' => $shipping_method->title,
|
||||
'shipping_method_id' => $shipping_method->id,
|
||||
'shipping_method_instance_id' => $shipping_method->instance_id,
|
||||
);
|
||||
} else {
|
||||
$shipping_methods[ $shipping_method->instance_id ] = $zone_data['zone_name'] . ': ' . $shipping_method->title;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $shipping_methods;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_woocommerce_package_rates_module_filter_priority' ) ) {
|
||||
/**
|
||||
* wcj_get_woocommerce_package_rates_module_filter_priority.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 3.2.4
|
||||
* @todo add `shipping_by_order_amount` module
|
||||
*/
|
||||
function wcj_get_woocommerce_package_rates_module_filter_priority( $module_id ) {
|
||||
$modules_priorities = array(
|
||||
'shipping_options_hide_free_shipping' => PHP_INT_MAX,
|
||||
'shipping_by_products' => PHP_INT_MAX - 100,
|
||||
'shipping_by_user_role' => PHP_INT_MAX - 100,
|
||||
'shipping_by_cities' => PHP_INT_MAX - 100,
|
||||
);
|
||||
return ( 0 != ( $priority = get_option( 'wcj_' . $module_id . '_filter_priority', 0 ) ) ?
|
||||
$priority :
|
||||
( isset( $modules_priorities[ $module_id ] ) ? $modules_priorities[ $module_id ] : PHP_INT_MAX )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_left_to_free_shipping' ) ) {
|
||||
/*
|
||||
* wcj_get_left_to_free_shipping.
|
||||
*
|
||||
* @version 3.6.0
|
||||
* @since 2.4.4
|
||||
* @return string
|
||||
* @todo (maybe) go through all packages instead of only `$packages[0]`
|
||||
*/
|
||||
function wcj_get_left_to_free_shipping( $content, $multiply_by = 1 ) {
|
||||
// "You have Free delivery"
|
||||
if ( function_exists( 'WC' ) && ( WC()->shipping ) && ( $packages = WC()->shipping->get_packages() ) ) {
|
||||
foreach ( $packages as $i => $package ) {
|
||||
$available_shipping_methods = $package['rates'];
|
||||
if ( wcj_is_module_enabled( 'shipping_by_user_role' ) ) {
|
||||
$available_shipping_methods = WCJ()->modules['shipping_by_user_role']->available_shipping_methods( $available_shipping_methods, false );
|
||||
}
|
||||
foreach ( $available_shipping_methods as $available_shipping_method ) {
|
||||
$method_id = ( WCJ_IS_WC_VERSION_BELOW_3_2_0 ? $available_shipping_method->method_id : $available_shipping_method->get_method_id() );
|
||||
if ( 'free_shipping' === $method_id ) {
|
||||
return do_shortcode( get_option( 'wcj_shipping_left_to_free_info_content_reached', __( 'You have Free delivery', 'woocommerce-jetpack' ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Getting `$min_free_shipping_amount`
|
||||
$min_free_shipping_amount = 0;
|
||||
if ( version_compare( WCJ_WC_VERSION, '2.6.0', '<' ) ) {
|
||||
$free_shipping = new WC_Shipping_Free_Shipping();
|
||||
if ( in_array( $free_shipping->requires, array( 'min_amount', 'either', 'both' ) ) ) {
|
||||
$min_free_shipping_amount = $free_shipping->min_amount;
|
||||
}
|
||||
} else {
|
||||
$legacy_free_shipping = new WC_Shipping_Legacy_Free_Shipping();
|
||||
if ( 'yes' === $legacy_free_shipping->enabled ) {
|
||||
if ( in_array( $legacy_free_shipping->requires, array( 'min_amount', 'either', 'both' ) ) ) {
|
||||
$min_free_shipping_amount = $legacy_free_shipping->min_amount;
|
||||
}
|
||||
}
|
||||
if ( 0 == $min_free_shipping_amount ) {
|
||||
if ( function_exists( 'WC' ) && ( $wc_shipping = WC()->shipping ) && ( $wc_cart = WC()->cart ) ) {
|
||||
if ( $wc_shipping->enabled ) {
|
||||
if ( $packages = $wc_cart->get_shipping_packages() ) {
|
||||
$shipping_methods = $wc_shipping->load_shipping_methods( $packages[0] );
|
||||
if ( wcj_is_module_enabled( 'shipping_by_user_role' ) ) {
|
||||
$shipping_methods = WCJ()->modules['shipping_by_user_role']->available_shipping_methods( $shipping_methods, false );
|
||||
}
|
||||
foreach ( $shipping_methods as $shipping_method ) {
|
||||
if ( 'yes' === $shipping_method->enabled && 0 != $shipping_method->instance_id ) {
|
||||
if ( 'WC_Shipping_Free_Shipping' === get_class( $shipping_method ) ) {
|
||||
if ( in_array( $shipping_method->requires, array( 'min_amount', 'either', 'both' ) ) ) {
|
||||
$min_free_shipping_amount = $shipping_method->min_amount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Outputting "left to free shipping"
|
||||
if ( 0 != $min_free_shipping_amount ) {
|
||||
if ( isset( WC()->cart ) ) {
|
||||
// Getting cart total
|
||||
$total = WC()->cart->get_displayed_subtotal();
|
||||
$is_cart_display_prices_including_tax = ( WCJ_IS_WC_VERSION_BELOW_3_3_0 ?
|
||||
( 'incl' === WC()->cart->tax_display_cart ) : WC()->cart->display_prices_including_tax() );
|
||||
if ( $is_cart_display_prices_including_tax ) {
|
||||
$total = round( $total - ( WC()->cart->get_discount_total() + WC()->cart->get_discount_tax() ), wc_get_price_decimals() );
|
||||
} else {
|
||||
$total = round( $total - WC()->cart->get_discount_total(), wc_get_price_decimals() );
|
||||
}
|
||||
// Final message
|
||||
if ( $total >= $min_free_shipping_amount ) {
|
||||
return do_shortcode( get_option( 'wcj_shipping_left_to_free_info_content_reached', __( 'You have Free delivery', 'woocommerce-jetpack' ) ) );
|
||||
} else {
|
||||
return wcj_handle_replacements( array(
|
||||
'%left_to_free%' => wc_price( ( $min_free_shipping_amount - $total ) * $multiply_by ),
|
||||
'%free_shipping_min_amount%' => wc_price( ( $min_free_shipping_amount ) * $multiply_by ),
|
||||
'%cart_total%' => wc_price( ( $total ) * $multiply_by ),
|
||||
), ( '' == $content ? __( '%left_to_free% left to free shipping', 'woocommerce-jetpack' ) : $content ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Booster for WooCommerce - Functions - Users
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.7.0
|
||||
* @author Algoritmika Ltd.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! function_exists( 'wcj_get_current_user_id' ) ) {
|
||||
/**
|
||||
* wcj_get_current_user_id.
|
||||
*
|
||||
* @version 3.5.0
|
||||
* @since 3.5.0
|
||||
*/
|
||||
function wcj_get_current_user_id() {
|
||||
if ( ! function_exists( 'get_current_user_id' ) ) {
|
||||
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
||||
}
|
||||
return get_current_user_id();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_users_as_options' ) ) {
|
||||
/**
|
||||
* wcj_get_users_as_options.
|
||||
*
|
||||
* @version 3.2.1
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_get_users_as_options() {
|
||||
$users = array();
|
||||
foreach ( get_users( 'orderby=display_name' ) as $user ) {
|
||||
$users[ $user->ID ] = $user->display_name . ' ' . '[ID:' . $user->ID . ']';
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'is_shop_manager' ) ) {
|
||||
/**
|
||||
* is_shop_manager.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @return bool
|
||||
*/
|
||||
function is_shop_manager( $user_id = 0 ) {
|
||||
$the_user = ( 0 == $user_id ) ? wp_get_current_user() : get_user_by( 'id', $user_id );
|
||||
return ( isset( $the_user->roles[0] ) && 'shop_manager' === $the_user->roles[0] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_current_user_all_roles' ) ) {
|
||||
/**
|
||||
* wcj_get_current_user_all_roles.
|
||||
*
|
||||
* @version 3.4.0
|
||||
* @since 2.5.6
|
||||
*/
|
||||
function wcj_get_current_user_all_roles() {
|
||||
if ( ! function_exists( 'wp_get_current_user' ) ) {
|
||||
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
return ( ! empty( $current_user->roles ) ) ? $current_user->roles : array( 'guest' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_user_logged_in' ) ) {
|
||||
/**
|
||||
* wcj_is_user_logged_in.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_is_user_logged_in() {
|
||||
if ( ! function_exists( 'is_user_logged_in' ) ) {
|
||||
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
||||
}
|
||||
return is_user_logged_in();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_booster_role_changer_enabled' ) ) {
|
||||
/**
|
||||
* wcj_is_booster_role_changer_enabled.
|
||||
*
|
||||
* @version 2.9.0
|
||||
* @since 2.9.0
|
||||
*/
|
||||
function wcj_is_booster_role_changer_enabled() {
|
||||
return (
|
||||
'yes' === apply_filters( 'booster_option', 'no', get_option( 'wcj_general_user_role_changer_enabled', 'no' ) ) &&
|
||||
wcj_is_user_logged_in() &&
|
||||
wcj_is_user_role( get_option( 'wcj_general_user_role_changer_enabled_for', array( 'administrator', 'shop_manager' ) ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_current_user_first_role' ) ) {
|
||||
/**
|
||||
* wcj_get_current_user_first_role.
|
||||
*
|
||||
* @version 3.2.2
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_get_current_user_first_role() {
|
||||
if ( wcj_is_module_enabled( 'general' ) && wcj_is_booster_role_changer_enabled() ) {
|
||||
$current_user_id = get_current_user_id();
|
||||
if ( '' != ( $role_by_meta = get_user_meta( $current_user_id, '_' . 'wcj_booster_user_role', true ) ) ) {
|
||||
return $role_by_meta;
|
||||
}
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
$first_role = ( isset( $current_user->roles ) && is_array( $current_user->roles ) && ! empty( $current_user->roles ) ? reset( $current_user->roles ) : 'guest' );
|
||||
return ( '' != $first_role ? $first_role : 'guest' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_user_roles' ) ) {
|
||||
/**
|
||||
* wcj_get_user_roles.
|
||||
*
|
||||
* @version 2.5.3
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_get_user_roles() {
|
||||
global $wp_roles;
|
||||
$all_roles = ( isset( $wp_roles ) && is_object( $wp_roles ) ) ? $wp_roles->roles : array();
|
||||
$all_roles = apply_filters( 'editable_roles', $all_roles );
|
||||
$all_roles = array_merge( array(
|
||||
'guest' => array(
|
||||
'name' => __( 'Guest', 'woocommerce-jetpack' ),
|
||||
'capabilities' => array(),
|
||||
) ), $all_roles );
|
||||
return $all_roles;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_get_user_roles_options' ) ) {
|
||||
/**
|
||||
* wcj_get_user_roles_options.
|
||||
*
|
||||
* @version 2.5.3
|
||||
* @since 2.5.3
|
||||
*/
|
||||
function wcj_get_user_roles_options() {
|
||||
global $wp_roles;
|
||||
$all_roles = ( isset( $wp_roles ) && is_object( $wp_roles ) ) ? $wp_roles->roles : array();
|
||||
$all_roles = apply_filters( 'editable_roles', $all_roles );
|
||||
$all_roles = array_merge( array(
|
||||
'guest' => array(
|
||||
'name' => __( 'Guest', 'woocommerce-jetpack' ),
|
||||
'capabilities' => array(),
|
||||
) ), $all_roles );
|
||||
$all_roles_options = array();
|
||||
foreach ( $all_roles as $_role_key => $_role ) {
|
||||
$all_roles_options[ $_role_key ] = $_role['name'];
|
||||
}
|
||||
return $all_roles_options;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wcj_is_user_role' ) ) {
|
||||
/**
|
||||
* wcj_is_user_role.
|
||||
*
|
||||
* @version 3.7.0
|
||||
* @since 2.5.0
|
||||
* @return bool
|
||||
* @todo clean up
|
||||
*/
|
||||
function wcj_is_user_role( $user_role, $user_id = 0 ) {
|
||||
if ( ! function_exists( 'wp_get_current_user' ) ) {
|
||||
include( ABSPATH . 'wp-includes/pluggable.php' );
|
||||
}
|
||||
$_user = ( 0 == $user_id ? wp_get_current_user() : get_user_by( 'id', $user_id ) );
|
||||
if ( ! isset( $_user->roles ) || empty( $_user->roles ) ) {
|
||||
$_user->roles = array( 'guest' );
|
||||
}
|
||||
if ( ! is_array( $_user->roles ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( is_array( $user_role ) ) {
|
||||
if ( in_array( 'administrator', $user_role ) ) {
|
||||
$user_role[] = 'super_admin';
|
||||
}
|
||||
$_intersect = array_intersect( $user_role, $_user->roles );
|
||||
return ( ! empty( $_intersect ) );
|
||||
} else {
|
||||
if ( 'administrator' == $user_role ) {
|
||||
return ( in_array( 'administrator', $_user->roles ) || in_array( 'super_admin', $_user->roles ) );
|
||||
} else {
|
||||
return ( in_array( $user_role, $_user->roles ) );
|
||||
}
|
||||
}
|
||||
/* if ( ! is_array( $user_role ) ) {
|
||||
$user_role = array( $user_role );
|
||||
}
|
||||
if ( in_array( 'administrator', $user_role ) ) {
|
||||
$user_role[] = 'super_admin';
|
||||
}
|
||||
$_intersect = array_intersect( $user_role, $_user->roles );
|
||||
return ( ! empty( $_intersect ) ); */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user