/** * recalculate_price_filter_products_prices. * * @version 2.5.6 * @since 2.5.6 */ function recalculate_price_filter_products_prices() { if (isset($_GET['recalculate_price_filter_products_prices']) && (wcj_is_user_role('administrator') || is_shop_manager())) { wcj_update_products_price_by_country(); global $wcj_notice; $wcj_notice = __('Price filter widget product prices recalculated.', 'woocommerce-jetpack'); } }
/** * 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 (!wcj_is_user_role('administrator') || 1 === apply_filters('booster_get_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'); } }
/** * create_wpml_xml_file. * * @version 2.5.0 * @since 2.4.1 */ function create_wpml_xml_file_tool() { if (!isset($_GET['create_wpml_xml_file']) || !wcj_is_user_role('administrator')) { return; } if (!isset($_GET['section']) || 'wpml' != $_GET['section']) { return; } $this->create_wpml_xml_file(); $this->notice = __('File wpml-config.xml successfully regenerated!', 'woocommerce-jetpack'); }
/** * add_eu_countries_vat_rates. * * @version 2.5.0 * @since 2.3.10 */ function add_eu_countries_vat_rates() { if (!isset($_POST['add_eu_countries_vat_rates'])) { return; } if (!wcj_is_user_role('administrator') && !is_shop_manager()) { return; } $loop = 0; foreach (wcj_get_european_union_countries_with_vat() as $country => $rate) { $tax_rate = array('tax_rate_country' => $country, 'tax_rate' => $rate, 'tax_rate_name' => isset($_POST['wcj_tax_name']) ? $_POST['wcj_tax_name'] : __('VAT', 'woocommerce'), 'tax_rate_priority' => 1, 'tax_rate_compound' => 0, 'tax_rate_shipping' => 1, 'tax_rate_order' => $loop++, 'tax_rate_class' => ''); $tax_rate_id = WC_Tax::_insert_tax_rate($tax_rate); WC_Tax::_update_tax_rate_postcodes($tax_rate_id, ''); WC_Tax::_update_tax_rate_cities($tax_rate_id, ''); } }
/** * handle_downloads. * * @version 2.5.0 * @since 2.2.2 */ public function handle_downloads() { if (isset($_GET['wcj_download_file'])) { $file_name = $_GET['wcj_download_file']; $upload_dir = wcj_get_wcj_uploads_dir('input_fields_uploads'); $file_path = $upload_dir . '/' . $file_name; if (wcj_is_user_role('administrator') || is_shop_manager()) { header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header('Content-disposition: attachment; filename=' . $file_name); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($file_path)); readfile($file_path); exit; } } }
/** * generate_report_zip. * * @version 2.5.0 * @since 2.3.10 */ function generate_report_zip() { if (isset($_POST['get_invoices_report_zip'])) { if (wcj_is_module_enabled('general') && 'yes' === get_option('wcj_general_advanced_disable_save_sys_temp_dir', 'no')) { $this->notice = '<div class="error"><p><strong>' . __('This option is disabled in WooCommerce > Settings > Booster > Emails & Misc. > General > Advanced Options > Disable Saving PDFs in PHP directory for temporary files', 'woocommerce-jetpack') . '</strong></p></div>'; } else { if (!empty($_POST['report_year']) && !empty($_POST['report_month']) && !empty($_POST['invoice_type'])) { if (wcj_is_user_role('administrator') || is_shop_manager()) { if (false === $this->get_invoices_report_zip($_POST['report_year'], $_POST['report_month'], $_POST['invoice_type'])) { $this->notice = '<div class="error"><p><strong>' . __('Sorry, but something went wrong...', 'woocommerce-jetpack') . '</strong></p></div>'; } } } else { $this->notice = '<div class="error"><p><strong>' . __('Please fill year and month values.', 'woocommerce-jetpack') . '</strong></p></div>'; } } } }
/** * wcj_get_user_location. * * @version 2.5.0 */ function wcj_get_user_location() { $country = ''; if (isset($_GET['country']) && '' != $_GET['country'] && wcj_is_user_role('administrator')) { $country = $_GET['country']; } else { // 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'))); } $country = isset($location['country']) ? $location['country'] : ''; } return $country; }
/** * reset_settings. * * @version 2.5.9 * @since 2.4.0 */ function reset_settings() { if (isset($_GET['wcj_reset_settings']) && $this->id === $_GET['wcj_reset_settings'] && wcj_is_user_role('administrator') && !isset($_POST['save'])) { foreach ($this->get_settings() as $settings) { $default_value = isset($settings['default']) ? $settings['default'] : ''; update_option($settings['id'], $default_value); } wp_safe_redirect(remove_query_arg('wcj_reset_settings')); exit; } }
/** * manage_options_reset. * * @version 2.5.2 * @since 2.5.2 */ function manage_options_reset() { global $wcj_notice; $delete_counter = 0; foreach ($this->modules as $module) { $values = $module->get_settings(); foreach ($values as $value) { if (isset($value['id'])) { if (isset($_POST['booster_reset_settings'])) { require_once ABSPATH . 'wp-includes/pluggable.php'; if (wcj_is_user_role('administrator')) { delete_option($value['id']); $delete_counter++; } } } } } if ($delete_counter > 0) { $wcj_notice .= sprintf(__('%d options successfully deleted.', 'woocommerce-jetpack'), $delete_counter); } }
/** * catch_args. * * @version 2.5.0 */ function catch_args() { $this->order_id = isset($_GET['order_id']) ? $_GET['order_id'] : 0; $this->invoice_type_id = isset($_GET['invoice_type_id']) ? $_GET['invoice_type_id'] : ''; $this->save_as_pdf = isset($_GET['save_pdf_invoice']) && '1' == $_GET['save_pdf_invoice'] ? true : false; $this->get_invoice = isset($_GET['get_invoice']) && '1' == $_GET['get_invoice'] ? true : false; if (isset($_GET['create_invoice_for_order_id']) && (wcj_is_user_role('administrator') || is_shop_manager())) { $this->create_document($_GET['create_invoice_for_order_id'], $this->invoice_type_id); } if (isset($_GET['delete_invoice_for_order_id']) && (wcj_is_user_role('administrator') || is_shop_manager())) { $this->delete_document($_GET['delete_invoice_for_order_id'], $this->invoice_type_id); } }
/** * process_checkout_files_upload. * * @version 2.5.0 * @since 2.4.5 */ function process_checkout_files_upload() { if (!session_id()) { session_start(); } // Remove file $total_number = apply_filters('booster_get_option', 1, get_option('wcj_checkout_files_upload_total_number', 1)); for ($i = 1; $i <= $total_number; $i++) { if (isset($_POST['wcj_remove_checkout_file_' . $i])) { if (isset($_POST['wcj_checkout_files_upload_order_id_' . $i])) { $order_id = $_POST['wcj_checkout_files_upload_order_id_' . $i]; $order_file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_' . $i, true); if ('' != $order_file_name) { $file_path = wcj_get_wcj_uploads_dir('checkout_files_upload') . '/' . $order_file_name; unlink($file_path); $file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_real_name_' . $i, true); wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_success_remove_' . $i, __('File "%s" was successfully removed.', 'woocommerce-jetpack')), $file_name)); delete_post_meta($order_id, '_' . 'wcj_checkout_files_upload_' . $i); delete_post_meta($order_id, '_' . 'wcj_checkout_files_upload_real_name_' . $i); } } else { $file_name = 'wcj_checkout_files_upload_' . $i; unlink($_SESSION[$file_name]['tmp_name']); wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_success_remove_' . $i, __('File "%s" was successfully removed.', 'woocommerce-jetpack')), $_SESSION[$file_name]['name'])); unset($_SESSION[$file_name]); } } } // Upload file for ($i = 1; $i <= $total_number; $i++) { if (isset($_POST['wcj_upload_checkout_file_' . $i])) { $file_name = 'wcj_checkout_files_upload_' . $i; if (isset($_FILES[$file_name]) && '' != $_FILES[$file_name]['tmp_name']) { // Validate $is_valid = true; if ('' != ($file_accept = get_option('wcj_checkout_files_upload_file_accept_' . $i, '')) && isset($_FILES[$file_name])) { // Validate file type $file_accept = explode(',', $file_accept); if (is_array($file_accept) && !empty($file_accept)) { $real_file_name = $_FILES[$file_name]['name']; $file_type = '.' . pathinfo($real_file_name, PATHINFO_EXTENSION); if (!in_array($file_type, $file_accept)) { wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_wrong_file_type_' . $i, __('Wrong file type: "%s"!', 'woocommerce-jetpack')), $real_file_name), 'error'); $is_valid = false; } } } if ($is_valid) { // To session $_SESSION[$file_name] = $_FILES[$file_name]; $tmp_dest_file = tempnam(sys_get_temp_dir(), 'wcj'); move_uploaded_file($_SESSION[$file_name]['tmp_name'], $tmp_dest_file); $_SESSION[$file_name]['tmp_name'] = $tmp_dest_file; wc_add_notice(sprintf(get_option('wcj_checkout_files_upload_notice_success_upload_' . $i, __('File "%s" was successfully uploaded.', 'woocommerce-jetpack')), $_SESSION[$file_name]['name'])); // To order if (isset($_POST['wcj_checkout_files_upload_order_id_' . $i])) { $this->add_files_to_order($_POST['wcj_checkout_files_upload_order_id_' . $i], null); } } } else { wc_add_notice(get_option('wcj_checkout_files_upload_notice_upload_no_file_' . $i, __('Please select file to upload!', 'woocommerce-jetpack')), 'notice'); } } } // Admin file download if (isset($_GET['wcj_download_checkout_file_admin'])) { $tmp_file_name = wcj_get_wcj_uploads_dir('checkout_files_upload') . '/' . $_GET['wcj_download_checkout_file_admin']; $file_name = get_post_meta($_GET['post'], '_' . 'wcj_checkout_files_upload_real_name_' . $_GET['wcj_checkout_file_number'], true); if (wcj_is_user_role('administrator') || is_shop_manager()) { header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header('Content-disposition: attachment; filename=' . $file_name); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($tmp_file_name)); readfile($tmp_file_name); exit; } } // User file download if (isset($_GET['wcj_download_checkout_file']) && isset($_GET['_wpnonce']) && false !== wp_verify_nonce($_GET['_wpnonce'], 'wcj_download_checkout_file')) { $i = $_GET['wcj_download_checkout_file']; if (isset($_GET['order-received']) || isset($_GET['view-order'])) { $order_id = isset($_GET['order-received']) ? $_GET['order-received'] : $_GET['view-order']; $the_order = wc_get_order($order_id); if (!$the_order->key_is_valid($_GET['key'])) { return; } $order_file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_' . $i, true); $tmp_file_name = wcj_get_wcj_uploads_dir('checkout_files_upload') . '/' . $order_file_name; $file_name = get_post_meta($order_id, '_' . 'wcj_checkout_files_upload_real_name_' . $i, true); } else { $tmp_file_name = $_SESSION['wcj_checkout_files_upload_' . $i]['tmp_name']; $file_name = $_SESSION['wcj_checkout_files_upload_' . $i]['name']; } header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header('Content-disposition: attachment; filename=' . $file_name); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($tmp_file_name)); readfile($tmp_file_name); exit; } }
/** * create_tool. * * @version 2.5.7 */ public function create_admin_tools_tool() { $the_notice = ''; if (isset($_GET['wcj_delete_log']) && wcj_is_user_role('administrator')) { update_option('wcj_log', ''); $the_notice .= __('Log deleted successfully.', 'woocommerce-jetpack'); } $the_tools = ''; $the_tools .= $this->get_tool_header_html('admin_tools'); $the_tools .= '<p><a href="' . add_query_arg('wcj_delete_log', '1') . '">' . __('Delete Log', 'woocommerce-jetpack') . '</a></p>'; $the_log = ''; $the_log .= '<pre>' . get_option('wcj_log', '') . '</pre>'; $html = ''; $html .= '<p>' . $the_tools . '</p>'; $html .= '<p>' . $the_notice . '</p>'; $html .= '<p>' . $the_log . '</p>'; echo $html; }
/** * get_customer_country_group_id. * * @version 2.5.6 */ public 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')) && isset(WC()->customer) && ('yes' === $override_option && '' != WC()->customer->get_country() || 'shipping_country' === $override_option && '' != WC()->customer->get_shipping_country())) { $country = 'yes' === $override_option ? WC()->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 = isset($_SESSION['wcj-country']) ? $_SESSION['wcj-country'] : $this->get_customer_country_by_ip(); } elseif ('by_user_selection' === get_option('wcj_price_by_country_customer_country_detection_method', 'by_ip')) { $country = isset($_SESSION['wcj-country']) ? $_SESSION['wcj-country'] : null; } 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_get_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; }