Enabled product bundles

This commit is contained in:
Nedim Uka
2018-06-29 14:40:28 +02:00
parent e0514f7f57
commit b5475ff2f1
12004 changed files with 1694047 additions and 1610 deletions

View File

@@ -0,0 +1,367 @@
<?php
/**
* Booster for WooCommerce - Price by Country - Core
*
* @version 3.6.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_Price_by_Country_Core' ) ) :
class WCJ_Price_by_Country_Core {
/**
* Constructor.
*
* @version 3.6.0
* @todo check if we can just always execute `init()` on `init` hook
*/
function __construct() {
$this->customer_country_group_id = null;
if ( ( 'no' === get_option( 'wcj_price_by_country_for_bots_disabled', 'no' ) || ! wcj_is_bot() ) && ! wcj_is_admin_product_edit_page() ) {
if ( in_array( get_option( 'wcj_price_by_country_customer_country_detection_method', 'by_ip' ), array( 'by_user_selection', 'by_ip_then_by_user_selection' ) ) ) {
if ( 'wc' === WCJ_SESSION_TYPE ) {
// `init()` executed on `init` hook because we need to use `WC()->session`
add_action( 'init', array( $this, 'init' ) );
} else {
$this->init();
}
}
$this->add_hooks();
// `maybe_init_customer_country_by_ip()` executed on `init` hook - in case we need to call `get_customer_country_by_ip()` `WC_Geolocation` class is ready
add_action( 'init', array( $this, 'maybe_init_customer_country_by_ip' ) );
}
}
/**
* init.
*
* @version 3.5.0
* @since 2.9.0
*/
function init() {
wcj_session_maybe_start();
if ( isset( $_REQUEST[ 'wcj-country' ] ) ) {
wcj_session_set( 'wcj-country', $_REQUEST[ 'wcj-country' ] );
}
if ( isset( $_REQUEST[ 'wcj_country_selector' ] ) ) {
wcj_session_set( 'wcj-country', $_REQUEST[ 'wcj_country_selector' ] );
}
}
/**
* maybe_init_customer_country_by_ip.
*
* @version 3.4.0
* @since 2.9.0
*/
function maybe_init_customer_country_by_ip() {
if ( 'by_ip_then_by_user_selection' === get_option( 'wcj_price_by_country_customer_country_detection_method', 'by_ip' ) ) {
if ( null === wcj_session_get( 'wcj-country' ) ) {
if ( null != ( $country = $this->get_customer_country_by_ip() ) ) {
wcj_session_set( 'wcj-country', $country );
}
}
}
}
/**
* add_hooks.
*
* @version 3.5.1
*/
function add_hooks() {
// Select with flags
if ( 'yes' === get_option( 'wcj_price_by_country_jquery_wselect_enabled', 'no' ) ) {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_wselect_scripts' ) );
}
$this->price_hooks_priority = wcj_get_module_price_hooks_priority( 'price_by_country' );
// Price hooks
wcj_add_change_price_hooks( $this, $this->price_hooks_priority );
// Currency hooks
add_filter( 'woocommerce_currency_symbol', array( $this, 'change_currency_symbol' ), $this->price_hooks_priority, 2 );
add_filter( 'woocommerce_currency', array( $this, 'change_currency_code' ), $this->price_hooks_priority, 1 );
// Price Filter Widget
if ( 'yes' === get_option( 'wcj_price_by_country_price_filter_widget_support_enabled', 'no' ) ) {
add_filter( 'woocommerce_price_filter_meta_keys', array( $this, 'price_filter_meta_keys' ), PHP_INT_MAX, 1 );
add_filter( 'woocommerce_product_query_meta_query', array( $this, 'price_filter_meta_query' ), PHP_INT_MAX, 2 );
add_filter( 'woocommerce_get_catalog_ordering_args', array( $this, 'sorting_by_price_fix' ), PHP_INT_MAX );
}
}
/**
* enqueue_wselect_scripts.
*
* @version 2.5.4
* @since 2.5.4
*/
function enqueue_wselect_scripts() {
wp_enqueue_style( 'wcj-wSelect-style', wcj_plugin_url() . '/includes/lib/wSelect/wSelect.css' );
wp_enqueue_script( 'wcj-wSelect', wcj_plugin_url() . '/includes/lib/wSelect/wSelect.min.js', array(), false, true );
wp_enqueue_script( 'wcj-wcj-wSelect', wcj_plugin_url() . '/includes/js/wcj-wSelect.js', array(), false, true );
}
/*
* sorting_by_price_fix.
*
* @version 2.7.0
* @since 2.5.6
*/
function sorting_by_price_fix( $args ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
// Get ordering from query string
$orderby_value = ( WCJ_IS_WC_VERSION_BELOW_3 ?
( isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ) ) :
( isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ) )
);
// Get orderby arg from string
$orderby_value = explode( '-', $orderby_value );
$orderby = esc_attr( $orderby_value[0] );
$orderby = strtolower( $orderby );
if ( 'price' == $orderby ) {
$args['meta_key'] = '_' . 'wcj_price_by_country_' . $group_id;
}
}
return $args;
}
/**
* price_filter_meta_query.
*
* @version 2.5.3
* @since 2.5.3
*/
function price_filter_meta_query( $meta_query, $_wc_query ) {
foreach ( $meta_query as $_key => $_query ) {
if ( isset( $_query['price_filter'] ) && true === $_query['price_filter'] && isset( $_query['key'] ) ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
$meta_query[ $_key ]['key'] = '_' . 'wcj_price_by_country_' . $group_id;
}
}
}
return $meta_query;
}
/**
* price_filter_meta_keys.
*
* @version 2.5.3
* @since 2.5.3
*/
function price_filter_meta_keys( $keys ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
$keys = array( '_' . 'wcj_price_by_country_' . $group_id );
}
return $keys;
}
/**
* change_price_grouped.
*
* @version 2.7.0
* @since 2.5.0
*/
function change_price_grouped( $price, $qty, $_product ) {
if ( $_product->is_type( 'grouped' ) ) {
if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled', 'yes' ) ) {
foreach ( $_product->get_children() as $child_id ) {
$the_price = get_post_meta( $child_id, '_price', true );
$the_product = wc_get_product( $child_id );
$the_price = wcj_get_product_display_price( $the_product, $the_price, 1 );
if ( $the_price == $price ) {
return $this->change_price( $price, $child_id );
}
}
} else {
return $this->change_price( $price, 0 );
}
}
return $price;
}
/**
* get_customer_country_by_ip.
*
* @version 2.5.1
* @since 2.5.0
*/
function get_customer_country_by_ip() {
if ( class_exists( 'WC_Geolocation' ) ) {
// Get the country by IP
$location = WC_Geolocation::geolocate_ip();
// 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'] : null;
} else {
return null;
}
}
/**
* change_price_shipping.
*
* @version 3.2.0
*/
function change_price_shipping( $package_rates, $package ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
$country_exchange_rate = get_option( 'wcj_price_by_country_exchange_rate_group_' . $group_id, 1 );
return wcj_change_price_shipping_package_rates( $package_rates, $country_exchange_rate );
} else {
return $package_rates;
}
}
/**
* get_customer_country_group_id.
*
* @version 3.4.0
* @todo ! "We already know the group - nothing to calculate - return group"
* @todo (maybe) add `cart_and_checkout` override option
*/
function get_customer_country_group_id() {
if ( 'yes' === get_option( 'wcj_price_by_country_revert', 'no' ) && is_checkout() ) {
$this->customer_country_group_id = -1;
return null;
}
// We already know the group - nothing to calculate - return group
/* if ( null != $this->customer_country_group_id && $this->customer_country_group_id > 0 ) {
return $this->customer_country_group_id;
} */
// Get the country
if ( isset( $_GET['country'] ) && '' != $_GET['country'] && wcj_is_user_role( 'administrator' ) ) {
$country = $_GET['country'];
} elseif ( 'no' != ( $override_option = get_option( 'wcj_price_by_country_override_on_checkout_with_billing_country', 'no' ) )
&& (
( 'all' === get_option( 'wcj_price_by_country_override_scope', 'all' ) ) ||
// ( 'cart_and_checkout' === get_option( 'wcj_price_by_country_override_scope', 'all' ) && ( is_cart() || is_checkout() ) ) ||
( 'checkout' === get_option( 'wcj_price_by_country_override_scope', 'all' ) && is_checkout() )
)
&& isset( WC()->customer )
&& ( ( 'yes' === $override_option && '' != wcj_customer_get_country() ) || ( 'shipping_country' === $override_option && '' != WC()->customer->get_shipping_country() ) )
) {
$country = ( 'yes' === $override_option ) ? wcj_customer_get_country() : WC()->customer->get_shipping_country();
} else {
if ( 'by_ip' === get_option( 'wcj_price_by_country_customer_country_detection_method', 'by_ip' ) ) {
$country = $this->get_customer_country_by_ip();
} elseif ( 'by_ip_then_by_user_selection' === get_option( 'wcj_price_by_country_customer_country_detection_method', 'by_ip' ) ) {
$country = ( null !== ( $session_value = wcj_session_get( 'wcj-country' ) ) ? $session_value : $this->get_customer_country_by_ip() );
} elseif ( 'by_user_selection' === get_option( 'wcj_price_by_country_customer_country_detection_method', 'by_ip' ) ) {
$country = wcj_session_get( 'wcj-country' );
} elseif ( 'by_wpml' === get_option( 'wcj_price_by_country_customer_country_detection_method', 'by_ip' ) ) {
$country = ( defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : null );
}
}
if ( null === $country ) {
$this->customer_country_group_id = -1;
return null;
}
// Get the country group id - go through all the groups, first found group is returned
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 ( is_array( $country_exchange_rate_group ) && in_array( $country, $country_exchange_rate_group ) ) {
$this->customer_country_group_id = $i;
return $i;
}
}
// No country group found
$this->customer_country_group_id = -1;
return null;
}
/**
* change_currency_symbol.
*/
function change_currency_symbol( $currency_symbol, $currency ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
$country_currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id );
if ( '' != $country_currency_code ) {
return wcj_get_currency_symbol( $country_currency_code );
}
}
return $currency_symbol;
}
/**
* change_currency_code.
*/
function change_currency_code( $currency ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
$country_currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id );
if ( '' != $country_currency_code ) {
return $country_currency_code;
}
}
return $currency;
}
/**
* get_variation_prices_hash.
*
* @version 2.6.0
* @since 2.4.3
*/
function get_variation_prices_hash( $price_hash, $_product, $display ) {
$group_id = $this->get_customer_country_group_id();
$price_hash['wcj_price_by_country_group_id_data'] = array(
$group_id,
get_option( 'wcj_price_by_country_rounding', 'none' ),
get_option( 'wcj_price_by_country_make_pretty', 'no' ),
get_option( 'wcj_price_by_country_make_pretty_min_amount_multiplier', 1 ),
get_option( 'woocommerce_price_num_decimals', 2 ),
get_option( 'wcj_price_by_country_local_enabled', 'yes' ),
// get_option( 'wcj_price_by_country_selection' ),
// get_option( 'wcj_price_by_country_total_groups_number' ),
// get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $group_id ),
// get_option( 'wcj_price_by_country_countries_group_' . $group_id ),
// get_option( 'wcj_price_by_country_countries_group_chosen_select_' . $group_id ),
get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id ),
get_option( 'wcj_price_by_country_exchange_rate_group_' . $group_id, 1 ),
get_option( 'wcj_price_by_country_make_empty_price_group_' . $group_id, 'no' ),
);
return $price_hash;
}
/**
* change_price.
*
* @version 2.7.0
*/
function change_price( $price, $product ) {
if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
return wcj_price_by_country( $price, $product, $group_id );
}
// No changes
return $price;
}
}
endif;
return new WCJ_Price_by_Country_Core();

View File

@@ -0,0 +1,130 @@
<?php
/**
* Booster for WooCommerce - Price By Country - Group Generator
*
* @version 2.5.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_Price_By_Country_Group_Generator' ) ) :
class WCJ_Price_By_Country_Group_Generator {
/**
* Constructor.
*
* @version 2.3.9
*/
function __construct() {
require_once( 'wcj-country-currency.php' );
add_action( 'woocommerce_init', array( $this, 'create_all_countries_groups' ) );
}
/**
* get_currency_countries.
*
* @version 2.3.9
*/
function get_currency_countries( $limit_currencies = '' ) {
$country_currency = wcj_get_country_currency();
if ( '' != $limit_currencies ) {
$default_currency = get_woocommerce_currency();
if ( 'paypal_only' === $limit_currencies || 'paypal_and_yahoo_exchange_rates_only' === $limit_currencies ) {
$paypal_supported_currencies = wcj_get_paypal_supported_currencies();
}
if ( 'yahoo_exchange_rates_only' === $limit_currencies || 'paypal_and_yahoo_exchange_rates_only' === $limit_currencies ) {
$yahoo_exchange_rates_supported_currencies = wcj_get_yahoo_exchange_rates_supported_currency();
}
}
$currencies = array();
foreach ( $country_currency as $country => $currency ) {
if ( 'paypal_only' === $limit_currencies ) {
if ( ! isset( $paypal_supported_currencies[ $currency ] ) ) {
$currency = $default_currency;
}
} elseif ( 'yahoo_exchange_rates_only' === $limit_currencies ) {
if ( ! isset( $yahoo_exchange_rates_supported_currencies[ $currency ] ) ) {
$currency = $default_currency;
}
} elseif ( 'paypal_and_yahoo_exchange_rates_only' === $limit_currencies ) {
if ( ! isset( $paypal_supported_currencies[ $currency ] ) || ! isset( $yahoo_exchange_rates_supported_currencies[ $currency ] ) ) {
$currency = $default_currency;
}
}
$currencies[ $currency ][] = $country;
}
return $currencies;
}
/**
* create_all_countries_groups.
*
* @version 2.5.0
*/
function create_all_countries_groups() {
global $wcj_notice;
if ( ! isset( $_GET['wcj_generate_country_groups'] ) ) {
return;
}
if ( isset( $_POST['save'] ) ) {
return;
}
if ( /* ! is_admin() || */ ! wcj_is_user_role( 'administrator' ) || 1 === apply_filters( 'booster_option', 1, '' ) ) {
$wcj_notice = __( 'Create All Country Groups Failed.', 'woocommerce-jetpack' );
return;
}
switch ( $_GET['wcj_generate_country_groups'] ) {
case 'all':
case 'paypal_only':
case 'yahoo_exchange_rates_only':
case 'paypal_and_yahoo_exchange_rates_only':
$currencies = $this->get_currency_countries( $_GET['wcj_generate_country_groups'] );
break;
default:
$wcj_notice = __( 'Create All Country Groups Failed. Wrong parameter.', 'woocommerce-jetpack' );
return;
}
$number_of_groups = count( $currencies );
if ( ! isset( $_GET['wcj_generate_country_groups_confirm'] ) ) {
$wcj_notice .= sprintf( __( 'All existing country groups will be deleted and %s new groups will be created. Are you sure?', 'woocommerce-jetpack' ), $number_of_groups );
$wcj_notice .= ' ' . '<a style="color: red !important;" href="' . add_query_arg( 'wcj_generate_country_groups_confirm', 'yes' ) . '">' . __( 'Confirm', 'woocommerce-jetpack' ) . '</a>.';
//$_GET['wc_message'] = __( 'Are you sure? Confirm.', 'woocommerce-jetpack' );
/* $wcj_notice .= '<p>';
$wcj_notice .= __( 'Preview', 'woocommerce-jetpack' ) . '<br>';
foreach ( $currencies as $group_currency => $countries ) {
$wcj_notice .= $group_currency . ' - ' . implode( ',', $countries ) . '<br>';
}
$wcj_notice .= '</p>'; */
} else {
update_option( 'wcj_price_by_country_total_groups_number', $number_of_groups );
$i = 0;
foreach ( $currencies as $group_currency => $countries ) {
$i++;
switch ( get_option( 'wcj_price_by_country_selection', 'comma_list' ) ) {
case 'comma_list':
update_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i, implode( ',', $countries ) );
break;
case 'multiselect':
update_option( 'wcj_price_by_country_countries_group_' . $i, $countries );
break;
case 'chosen_select':
update_option( 'wcj_price_by_country_countries_group_chosen_select_' . $i, $countries );
break;
}
update_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i, $group_currency );
update_option( 'wcj_price_by_country_exchange_rate_group_' . $i, 1 );
update_option( 'wcj_price_by_country_make_empty_price_group_' . $i, 'no' );
}
$wcj_notice = __( 'Country Groups Generated.', 'woocommerce-jetpack' );
}
}
}
endif;
return new WCJ_Price_By_Country_Group_Generator();

View File

@@ -0,0 +1,249 @@
<?php
/**
* Booster for WooCommerce - Price by Country - Local
*
* @version 3.3.0
* @author Algoritmika Ltd.
* @todo (maybe) remove this and leave only standard meta box option (i.e. only `'meta_box' === get_option( 'wcj_price_by_country_local_options_style', 'inline' )`)
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'WCJ_Price_by_Country_Local' ) ) :
class WCJ_Price_by_Country_Local {
/**
* Constructor.
*
* @version 2.3.9
*/
function __construct() {
add_action( 'woocommerce_ajax_save_product_variations', array( $this, 'save_custom_meta_box_on_product_edit_ajax' ), PHP_INT_MAX, 1 );
add_action( 'save_post_product', array( $this, 'save_custom_meta_box_on_product_edit' ), PHP_INT_MAX, 2 );
add_action( 'woocommerce_product_options_pricing', array( $this, 'add_simple_pricing' ), PHP_INT_MAX, 0 );
add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'add_variable_pricing' ), PHP_INT_MAX, 3 );
add_action( 'woocommerce_product_options_general_product_data', array( $this, 'add_hidden_save' ), PHP_INT_MAX, 0 );
add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'add_hidden_save' ), PHP_INT_MAX, 0 );
}
/**
* add_simple_pricing.
*/
function add_simple_pricing() {
$this->create_custom_meta_box( 'simple' );
}
/**
* add_variable_pricing.
*/
function add_variable_pricing( $loop, $variation_data, $variation ) {
$this->create_custom_meta_box( 'variable', $variation->ID );
}
/**
* create_custom_meta_box.
*/
function create_custom_meta_box( $simple_or_variable, $product_id = 0 ) {
$current_post_id = ( $product_id == 0) ? get_the_ID() : $product_id;
$the_product = wc_get_product( $current_post_id );
if ( ! $the_product ) {
return;
}
$total_country_groups_number = $this->get_total_country_groups_number();
// Start html
$html = '';
if ( $the_product->is_type( 'variation' ) ) {
$html .= $this->get_all_options_html( $simple_or_variable, $current_post_id, $total_country_groups_number, '_' . $current_post_id );
} else {
$html .= $this->get_all_options_html( $simple_or_variable, $current_post_id, $total_country_groups_number );
}
// Output
echo $html;
}
/**
* add_hidden_save.
*/
function add_hidden_save() {
$meta_box_id = 'price_by_country';
echo '<input type="hidden" name="woojetpack_' . $meta_box_id . '_save_post" value="woojetpack_' . $meta_box_id . '_save_post">';
}
/**
* get_total_country_groups_number.
*/
function get_total_country_groups_number() {
return apply_filters( 'booster_option', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) );
}
/**
* get_prices_options.
*/
function get_prices_options() {
$meta_box_id = 'price_by_country';
$this->scope = 'local';
$options = array(
array(
'id' => 'wcj_' . $meta_box_id . '_regular_price_' . $this->scope . '_',
'title' => __( 'Regular Price', 'woocommerce' ),
'type' => 'text',
'default' => 0,
),
array(
'id' => 'wcj_' . $meta_box_id . '_sale_price_' . $this->scope . '_',
'title' => __( 'Sale Price', 'woocommerce' ),
'type' => 'text',
'default' => 0,
),
array(
'id' => 'wcj_' . $meta_box_id . '_make_empty_price_' . $this->scope . '_',
'title' => __( 'Make empty price', 'woocommerce-jetpack' ),
'type' => 'checkbox',
'default' => 'off',
),
);
return $options;
}
/**
* Save options.
*/
function save_options( $post_id, $total_options_groups, $variation_id_addon = '' ) {
$options = $this->get_prices_options();
for ( $i = 1; $i <= $total_options_groups; $i++ ) {
foreach ( $options as $option ) {
if ( isset( $_POST[ $option['id'] . $i . $variation_id_addon ] ) ) {
update_post_meta( $post_id, '_' . $option['id'] . $i, $_POST[ $option['id'] . $i . $variation_id_addon ] );
}
elseif ( 'checkbox' === $option['type'] ) {
update_post_meta( $post_id, '_' . $option['id'] . $i, 'off' );
}
}
}
}
/**
* Save Custom Meta Box on Product Edit - variations "Save Changes" button (ajax).
*
* @version 2.3.9
* @since 2.3.9
*/
function save_custom_meta_box_on_product_edit_ajax( $product_id ) {
return $this->save_custom_meta_box_on_product_edit( $product_id, /* 'ajax' */ null );
}
/**
* Save Custom Meta Box on Product Edit.
*/
function save_custom_meta_box_on_product_edit( $post_id, $post ) {
$meta_box_id = 'price_by_country';
// Check that we are saving with custom meta box displayed.
if ( ! isset( $_POST[ 'woojetpack_' . $meta_box_id . '_save_post' ] ) )
return;
$the_product = wc_get_product( $post_id );
if ( ! $the_product )
return;
$total_options_groups = $this->get_total_country_groups_number();
if ( $the_product->is_type( 'variable' ) ) {
$variations = $the_product->get_available_variations();
if ( empty( $variations ) ) {
return;
}
foreach ( $variations as $variation ) {
$this->save_options( $variation['variation_id'], $total_options_groups, '_' . $variation['variation_id'] );
}
}
else {
$this->save_options( $post_id, $total_options_groups );
}
}
/**
* get_option_field_html.
*/
function get_option_field_html( $current_post_id, $option_id, $option, $variation_id_addon = '' ) {
$html = '';
$option_value = get_post_meta( $current_post_id, '_' . $option_id, true );
$option_id .= $variation_id_addon;
$html .= wcj_get_option_html( $option['type'], $option_id, $option_value, '', 'short' );
return $html;
}
/**
* get_all_options_html.
*
* @version 3.3.0
*/
function get_all_options_html( $simple_or_variable, $current_post_id, $total_number, $variation_id_addon = '' ) {
$html = '';
$options = $this->get_prices_options();
for ( $i = 1; $i <= $total_number; $i++ ) {
if ( 'variable' == $simple_or_variable ) {
$html .= '<div>';
}
$countries = '';
switch ( get_option( 'wcj_price_by_country_selection', 'comma_list' ) ) {
case 'comma_list':
$countries .= get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
break;
case 'multiselect':
$countries .= implode( ',', get_option( 'wcj_price_by_country_countries_group_' . $i ) );
break;
case 'chosen_select':
$countries .= implode( ',', get_option( 'wcj_price_by_country_countries_group_chosen_select_' . $i ) );
break;
}
$admin_title = get_option( 'wcj_price_by_country_countries_group_admin_title_' . $i, __( 'Group', 'woocommerce-jetpack' ) . ' #' . $i );
$html .= '<details style="float: left; border-top: 1px dashed #cccccc; width: 100%; padding-top: 10px;">' .
'<summary style="font-weight:bold;">' . $admin_title . '</summary><p>' . $countries . '</p>' .
'</details>';
foreach ( $options as $option ) {
$option_id = $option['id'] . $i;
if ( 'simple' == $simple_or_variable ) {
$html .= '<p class="form-field ' . $option_id . $variation_id_addon . '_field">';
} else {
$column_position = 'full';
if ( 'checkbox' != $option['type'] ) {
$column_position = ( false !== strpos( $option['id'], '_regular_price_' ) ) ? 'first' : 'last';
}
$html .= '<p class="form-row form-row-' . $column_position . '">';
}
$group_currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i );
$currency_code_html = ( 'checkbox' != $option['type'] ) ? ' (' . wcj_get_currency_symbol( $group_currency_code ) . ')' : '';
$html .= '<label for="' . $option_id . $variation_id_addon . '">' . $option['title'] . $currency_code_html . '</label>';
$html .= $this->get_option_field_html( $current_post_id, $option_id, $option, $variation_id_addon );
$html .= '</p>';
}
if ( 'variable' == $simple_or_variable ) {
$html .= '</div>';
}
}
return $html;
}
}
endif;
return new WCJ_Price_by_Country_Local();

View File

@@ -0,0 +1,469 @@
<?php
/**
* Booster for WooCommerce Country Currency functions
*
* @version 3.3.0
* @author Algoritmika Ltd.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! function_exists( 'wcj_get_yahoo_exchange_rates_supported_currency' ) ) {
/**
* wcj_get_yahoo_exchange_rates_supported_currency.
*
* @version 3.3.0
*/
function wcj_get_yahoo_exchange_rates_supported_currency() {
return array(
'KRW' => true,
'XAG' => true,
'VND' => true,
'BOB' => true,
'MOP' => true,
'BDT' => true,
'MDL' => true,
'VEF' => true,
'GEL' => true,
'ISK' => true,
'BYN' => true,
'THB' => true,
'MXV' => true,
'TND' => true,
'JMD' => true,
'DKK' => true,
'SRD' => true,
'BWP' => true,
'NOK' => true,
'MUR' => true,
'AZN' => true,
'INR' => true,
'MGA' => true,
'CAD' => true,
'XAF' => true,
'LBP' => true,
'XDR' => true,
'IDR' => true,
'IEP' => true,
'AUD' => true,
'MMK' => true,
'LYD' => true,
'ZAR' => true,
'IQD' => true,
'XPF' => true,
'TJS' => true,
'CUP' => true,
'UGX' => true,
'NGN' => true,
'PGK' => true,
'TOP' => true,
'TMT' => true,
'KES' => true,
'CRC' => true,
'MZN' => true,
'SYP' => true,
'ANG' => true,
'ZMW' => true,
'BRL' => true,
'BSD' => true,
'NIO' => true,
'GNF' => true,
'BMD' => true,
'SLL' => true,
'MKD' => true,
'BIF' => true,
'LAK' => true,
'BHD' => true,
'SHP' => true,
'BGN' => true,
'SGD' => true,
'CNY' => true,
'EUR' => true,
'TTD' => true,
'SCR' => true,
'BBD' => true,
'SBD' => true,
'MAD' => true,
'GTQ' => true,
'MWK' => true,
'PKR' => true,
'ITL' => true,
'PEN' => true,
'AED' => true,
'LVL' => true,
'XPD' => true,
'UAH' => true,
'FRF' => true,
'LRD' => true,
'LSL' => true,
'SEK' => true,
'RON' => true,
'XOF' => true,
'COP' => true,
'CDF' => true,
'USD' => true,
'TZS' => true,
'GHS' => true,
'NPR' => true,
'ZWL' => true,
'SOS' => true,
'DZD' => true,
'FKP' => true,
'LKR' => true,
'JPY' => true,
'CHF' => true,
'KYD' => true,
'CLP' => true,
'IRR' => true,
'AFN' => true,
'DJF' => true,
'SVC' => true,
'PLN' => true,
'PYG' => true,
'ERN' => true,
'ETB' => true,
'ILS' => true,
'TWD' => true,
'KPW' => true,
'SIT' => true,
'GIP' => true,
'BND' => true,
'HNL' => true,
'CZK' => true,
'HUF' => true,
'BZD' => true,
'DEM' => true,
'JOD' => true,
'RWF' => true,
'LTL' => true,
'RUB' => true,
'RSD' => true,
'WST' => true,
'XPT' => true,
'NAD' => true,
'PAB' => true,
'DOP' => true,
'ALL' => true,
'HTG' => true,
'AMD' => true,
'KMF' => true,
'MRO' => true,
'HRK' => true,
'ECS' => true,
'KHR' => true,
'PHP' => true,
'CYP' => true,
'KWD' => true,
'XCD' => true,
'XCP' => true,
'CNH' => true,
'SDG' => true,
'CLF' => true,
'KZT' => true,
'TRY' => true,
'FJD' => true,
'NZD' => true,
'BAM' => true,
'BTN' => true,
'STD' => true,
'VUV' => true,
'MVR' => true,
'AOA' => true,
'EGP' => true,
'QAR' => true,
'OMR' => true,
'CVE' => true,
'KGS' => true,
'MXN' => true,
'MYR' => true,
'GYD' => true,
'SZL' => true,
'YER' => true,
'SAR' => true,
'UYU' => true,
'GBP' => true,
'UZS' => true,
'GMD' => true,
'AWG' => true,
'MNT' => true,
'XAU' => true,
'HKD' => true,
'ARS' => true,
);
}
}
if ( ! function_exists( 'wcj_get_paypal_supported_currencies' ) ) {
/**
* wcj_get_paypal_supported_currencies.
*
* @version 2.3.9
*/
function wcj_get_paypal_supported_currencies() {
return array(
'AUD' => true,
'BRL' => true,
'CAD' => true,
'CHF' => true,
'CZK' => true,
'DKK' => true,
'EUR' => true,
'GBP' => true,
'HKD' => true,
'HUF' => true,
'ILS' => true,
'JPY' => true,
'MYR' => true,
'MXN' => true,
'NOK' => true,
'NZD' => true,
'PHP' => true,
'PLN' => true,
'RUB' => true,
'SEK' => true,
'SGD' => true,
'THB' => true,
'TRY' => true,
'TWD' => true,
'USD' => true,
);
}
}
if ( ! function_exists( 'wcj_get_country_currency' ) ) {
/**
* wcj_get_country_currency.
*
* @version 3.3.0
*/
function wcj_get_country_currency() {
return array(
'ZW' => 'ZAR',
'BT' => 'BTN',
'BN' => 'BND',
'KH' => 'KHR',
'CU' => 'CUP',
'IM' => 'GBP',
'JE' => 'JEP',
'LS' => 'LSL',
'NA' => 'NAD',
'PS' => 'JOD',
'PA' => 'PAB',
'SG' => 'SGD',
'UA' => 'UAH',
'AF' => 'AFN',
'AL' => 'ALL',
'DZ' => 'DZD',
'AD' => 'EUR',
'AO' => 'AOA',
'AI' => 'XCD',
'AG' => 'XCD',
'AR' => 'ARS',
'AM' => 'AMD',
'AW' => 'AWG',
'AU' => 'AUD',
'AT' => 'EUR',
'AZ' => 'AZN',
'BS' => 'BSD',
'BH' => 'BHD',
'BD' => 'BDT',
'BB' => 'BBD',
'BY' => 'BYN',
'BE' => 'EUR',
'BZ' => 'BZD',
'BJ' => 'XOF',
'BM' => 'BMD',
'BO' => 'BOB',
'BQ' => 'USD',
'BA' => 'BAM',
'BW' => 'BWP',
'BR' => 'BRL',
'IO' => 'USD',
'VG' => 'USD',
'BG' => 'BGN',
'BF' => 'XOF',
'BI' => 'BIF',
'KY' => 'KYD',
'CM' => 'XAF',
'CA' => 'CAD',
'CV' => 'CVE',
'CF' => 'XAF',
'TD' => 'XAF',
'CL' => 'CLP',
'CN' => 'CNY',
'CY' => 'EUR',
'CC' => 'AUD',
'CO' => 'COP',
'KM' => 'KMF',
'CG' => 'CDF',
'CK' => 'NZD',
'CR' => 'CRC',
'CI' => 'XOF',
'HR' => 'HRK',
'CW' => 'ANG',
'CZ' => 'CZK',
'DK' => 'DKK',
'DJ' => 'DJF',
'DM' => 'XCD',
'DO' => 'DOP',
'TP' => 'USD',
'EC' => 'USD',
'EG' => 'EGP',
'SV' => 'USD',
'GQ' => 'XAF',
'ER' => 'ERN',
'EE' => 'EUR',
'ET' => 'ETB',
'FK' => 'FKP',
'FO' => 'DKK',
'FJ' => 'FJD',
'FI' => 'EUR',
'FR' => 'EUR',
'PF' => 'XPF',
'GA' => 'XAF',
'GM' => 'GMD',
'GE' => 'GEL',
'DE' => 'EUR',
'GH' => 'GHS',
'GI' => 'GIP',
'GR' => 'EUR',
'GD' => 'XCD',
'GT' => 'GTQ',
'GG' => 'GBP',
'GY' => 'GYD',
'GN' => 'GNF',
'GW' => 'XOF',
'HT' => 'HTG',
'HN' => 'HNL',
'HK' => 'HKD',
'HU' => 'HUF',
'IS' => 'ISK',
'YE' => 'YER',
'IN' => 'INR',
'ID' => 'IDR',
'IR' => 'IRR',
'IQ' => 'IQD',
'IE' => 'EUR',
'IL' => 'ILS',
'IT' => 'EUR',
'JM' => 'JMD',
'JP' => 'JPY',
'JO' => 'JOD',
'KZ' => 'KZT',
'KE' => 'KES',
'KG' => 'KGS',
'KI' => 'AUD',
'KP' => 'KPW',
'KR' => 'KRW',
'XK' => 'EUR',
'KW' => 'KWD',
'LA' => 'LAK',
'LV' => 'EUR',
'LB' => 'LBP',
'LR' => 'LRD',
'LY' => 'LYD',
'LI' => 'CHF',
'LT' => 'EUR',
'LU' => 'EUR',
'MO' => 'MOP',
'MK' => 'MKD',
'MG' => 'MGA',
'MY' => 'MYR',
'MW' => 'MWK',
'MV' => 'MVR',
'ML' => 'XOF',
'MT' => 'EUR',
'MH' => 'USD',
'MR' => 'MRO',
'MU' => 'MUR',
'MX' => 'MXN',
'MM' => 'MMK',
'FM' => 'USD',
'MD' => 'MDL',
'MC' => 'EUR',
'MN' => 'MNT',
'ME' => 'EUR',
'MS' => 'XCD',
'MA' => 'MAD',
'MZ' => 'MZN',
'NR' => 'AUD',
'NP' => 'NPR',
'NL' => 'EUR',
'NC' => 'XPF',
'NZ' => 'NZD',
'NI' => 'NIO',
'NE' => 'XOF',
'NG' => 'NGN',
'NU' => 'NZD',
'NO' => 'NOK',
'OM' => 'OMR',
'PK' => 'PKR',
'PW' => 'USD',
'PG' => 'PGK',
'PY' => 'PYG',
'PE' => 'PEN',
'PH' => 'PHP',
'PN' => 'NZD',
'PL' => 'PLN',
'PT' => 'EUR',
'QA' => 'QAR',
'RO' => 'RON',
'RU' => 'RUB',
'RW' => 'RWF',
'SH' => 'SHP',
'KN' => 'XCD',
'LC' => 'XCD',
'VC' => 'XCD',
'WS' => 'WST',
'SM' => 'EUR',
'ST' => 'STD',
'SA' => 'SAR',
'SC' => 'SCR',
'SN' => 'XOF',
'RS' => 'RSD',
'SL' => 'SLL',
'SX' => 'ANG',
'SY' => 'SYP',
'SK' => 'EUR',
'SI' => 'EUR',
'SB' => 'SBD',
'SO' => 'SOS',
'ZA' => 'ZAR',
'GS' => 'GBP',
'SS' => 'SSP',
'ES' => 'EUR',
'LK' => 'LKR',
'SD' => 'SDG',
'SR' => 'SRD',
'SZ' => 'SZL',
'SE' => 'SEK',
'CH' => 'CHF',
'TW' => 'TWD',
'TJ' => 'TJS',
'TZ' => 'TZS',
'TH' => 'THB',
'TG' => 'XOF',
'TO' => 'TOP',
'TT' => 'TTD',
'SH' => 'SHP',
'TN' => 'TND',
'TR' => 'TRY',
'TM' => 'TMT',
'TC' => 'USD',
'TV' => 'AUD',
'UG' => 'UGX',
'AE' => 'AED',
// 'UK' => 'GBP',
'GB' => 'GBP',
'US' => 'USD',
'UY' => 'UYU',
'UZ' => 'UZS',
'VU' => 'VUV',
'VA' => 'EUR',
'VE' => 'VEF',
'VN' => 'VND',
'WF' => 'XPF',
'ZM' => 'ZMW',
);
}
}