/** * Sets wcpbc data form country. * * @access public * @param mixed $country */ public function set_country($country) { $this->_data = array(); foreach (WCPBC()->get_regions() as $key => $group_data) { if (in_array($country, $group_data['countries'])) { $this->_data = array_merge($group_data, array('group_key' => $key, 'timestamp' => time())); break; } } $this->_changed = true; }
/** * Output manual country select form */ public function country_select() { $all_countries = WC()->countries->get_countries(); $base_country = wc_get_base_location(); $countries[$base_country['country']] = $all_countries[$base_country['country']]; foreach (WCPBC()->get_regions() as $region) { foreach ($region['countries'] as $country) { if (!array_key_exists($country, $countries)) { $countries[$country] = $all_countries[$country]; } } } asort($countries); $other_country = key(array_diff_key($all_countries, $countries)); $countries[$other_country] = apply_filters('wcpbc_other_countries_text', __('Other countries')); wc_get_template('country-selector.php', array('countries' => $countries), 'woocommerce-product-price-based-on-countries/', WCPBC()->plugin_path() . '/templates/'); }
/** * Handle updates */ public static function update_actions() { if (!empty($_GET['do_update_wc_price_based_country'])) { $install_version = self::get_install_version(); $db_updates = array('1.3.2' => 'updates/wcpbc-update-1.3.2.php'); foreach ($db_updates as $version => $updater) { if (version_compare($install_version, $version, '<')) { include $updater; } } update_option('wc_price_based_country_version', WCPBC()->version); } if (isset($_GET['wc_price_based_country_donate_hide']) && $_GET['wc_price_based_country_donate_hide']) { update_option('wc_price_based_country_hide_ads', 'yes'); } }
/** * Save global settings */ public function save() { global $current_section; if ($current_section) { if ($this->section_save()) { update_option('wc_price_based_country_timestamp', time()); } } else { if (isset($_POST['delete_group'])) { $section_settings = WCPBC()->get_regions(); global $wpdb; foreach ($_POST['delete_group'] as $region_key) { unset($section_settings[$region_key]); foreach (array('_price', '_regular_price', '_sale_price', '_price_method') as $price_type) { foreach (array('', '_variable') as $variable) { $meta_key = '_' . $region_key . $variable . $price_type; $wpdb->delete($wpdb->postmeta, array('meta_key' => $meta_key)); } if ($price_type !== '_price_method') { foreach (array('_min', '_max') as $min_or_max) { $meta_key = '_' . $region_key . $min_or_max . $price_type . '_variation_id'; $wpdb->delete($wpdb->postmeta, array('meta_key' => $meta_key)); } } } } update_option('wc_price_based_country_regions', $section_settings); } //save settings $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); update_option('wc_price_based_country_timestamp', time()); } }
function load_admin_script() { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('wc-price-based-country-admin', WCPBC()->plugin_url() . 'assets/js/wcpbc-admin' . $suffix . '.js', array('jquery'), WCPBC()->version, true); }
{ return plugin_dir_path(__FILE__); } } //End Class /** * Returns the main instance of WC_Product_Price_Based_Country to prevent the need to use globals. * * @since 1.3.0 * @return WC_Product_Price_Based_Country */ function WCPBC() { return WC_Product_Price_Based_Country::instance(); } $wc_product_price_based_country = WCPBC(); } // ! class_exists( 'WC_Product_Price_Based_Country' ) } else { add_action('admin_init', 'oga_wppbc_deactivate'); function oga_wppbc_deactivate() { deactivate_plugins(plugin_basename(__FILE__)); } add_action('admin_notices', 'oga_wppbc_no_woocommerce_admin_notice'); function oga_wppbc_no_woocommerce_admin_notice() { ?> <div class="updated"> <p><strong>WooCommerce Product Price Based on Countries</strong> has been deactivated because <a href="http://woothemes.com/">Woocommerce plugin</a> is required</p> </div>