/** * Check authentication of access credentials */ public function gf_auth_check() { $auth = $GLOBALS['wc_graphflow']->get_api()->test_auth(); if ($auth) { $notice_text = "Your Graphflow access keys have been verified!"; WC_Admin_Settings::add_message($notice_text); } else { $notice_text = "Your Graphflow access keys failed verification. Please check your Graphflow Account Page to retrieve the correct keys."; WC_Admin_Settings::add_error($notice_text); } }
public function save_settings() { WC_Admin_Settings::save_fields($this->settings); $is_api_working = $this->check_api() ? 1 : 0; update_option(WC_SiftScience_Options::$is_api_setup, $is_api_working); if ($is_api_working === 1) { WC_Admin_Settings::add_message('API is correctly configured'); } else { WC_Admin_Settings::add_error('API settings are broken'); } }
/** * Save the Targets settings */ public function save() { try { $this->verify_request(WooCommerce_Grow_Helpers::get_field('_wpnonce', $_REQUEST), 'woocommerce-grow-targets'); $is_calculate_growth = null !== WooCommerce_Grow_Helpers::get_field('calculate_growth', $_POST) ? true : false; // Calculate and Growth settings if ($is_calculate_growth) { $initial_revenue_number = WooCommerce_Grow_Helpers::get_field('initial_revenue_number', $_POST); $initial_orders_number = WooCommerce_Grow_Helpers::get_field('initial_orders_number', $_POST); $initial_sessions_number = WooCommerce_Grow_Helpers::get_field('initial_sessions_number', $_POST); $initial_cr_number = WooCommerce_Grow_Helpers::get_field('initial_cr_number', $_POST); $initial_aov_number = WooCommerce_Grow_Helpers::get_field('initial_aov_number', $_POST); // Call to GA to get sessions for the last month $ga = WooCommerce_Grow_Google_Analytics::get_instance(); $month = date('m', strtotime('first day of previous month')); $year = date('Y'); list($start_date, $end_date) = WooCommerce_Grow_Helpers::get_first_and_last_of_the_month($month, $year); $initial_sessions = $ga->get_sessions_for_month($month, $year); $filters = array('date_min' => $start_date, 'date_max' => $end_date); $reports = WooCommerce_Grow_Helpers::setup_wc_reports($filters); $initial_revenue = WooCommerce_Grow_Helpers::get_wc_total_sales($reports); $initial_orders = WooCommerce_Grow_Helpers::get_wc_total_orders($reports); WooCommerce_Grow_Helpers::add_debug_log('Revenue: ' . $initial_revenue); WooCommerce_Grow_Helpers::add_debug_log('Orders: ' . $initial_orders); $initial_cr = WooCommerce_Grow_Helpers::calculate_cr($initial_orders, $initial_sessions); $initial_aov = WooCommerce_Grow_Helpers::calculate_aov($initial_revenue, $initial_orders); $growth_rate = WooCommerce_Grow_Helpers::get_field('growth_rate', $_POST); // Save the initial options WooCommerce_Grow_Helpers::update_option('initial_revenue_number', $initial_revenue); WooCommerce_Grow_Helpers::update_option('initial_orders_number', $initial_orders); WooCommerce_Grow_Helpers::update_option('initial_sessions_number', $initial_sessions); WooCommerce_Grow_Helpers::update_option('initial_cr_number', $initial_cr); WooCommerce_Grow_Helpers::update_option('initial_aov_number', $initial_aov); WooCommerce_Grow_Helpers::update_option('growth_rate', $growth_rate); $months = WooCommerce_Grow_Helpers::get_twelve_months_ahead(); foreach ($months as $month) { $target_sessions = WooCommerce_Grow_Helpers::calculate_growth($initial_sessions, $growth_rate); $target_cr = WooCommerce_Grow_Helpers::calculate_growth($initial_cr, $growth_rate); $target_aov = WooCommerce_Grow_Helpers::calculate_growth($initial_aov, $growth_rate); $targets['sessions_percentage'][$month['year']][$month['month']] = ceil($target_sessions); $targets['cr_percentage'][$month['year']][$month['month']] = $target_cr; $targets['aov_percentage'][$month['year']][$month['month']] = $target_aov; $targets['revenue_percentage'][$month['year']][$month['month']] = wc_format_decimal($target_sessions * $target_cr * $target_aov, 2); $targets['orders_percentage'][$month['year']][$month['month']] = ceil($target_sessions * $target_cr); } WooCommerce_Grow_Helpers::update_option('monthly_targets', $targets); } } catch (Exception $e) { WC_Admin_Settings::add_error($e->getMessage()); } }
function woogle_update_license_key_status() { $result = woogle_activate_license_key(); if ($result == NULL) { update_option('woogle_license_key_validated', '0'); update_option('woogle_license_key_expires', '0'); WC_Admin_Settings::add_error(__('Your Woogle License Key is invalid!', 'woogle')); } elseif ($result->license == 'valid' || $result->license == 'expired') { update_option('woogle_license_key_validated', '1'); update_option('woogle_license_key_expires', $result->expires); WC_Admin_Settings::add_message(__('Your Woogle License Key is valid!', 'woogle')); } else { update_option('woogle_license_key_validated', '0'); update_option('woogle_license_key_expires', '0'); WC_Admin_Settings::add_error(__('Your Woogle License Key is invalid!', 'woogle')); } }
public function check_pdf_template_version($settings) { $templates = array('woocommerce_gzdp_invoice_template_attachment', 'woocommerce_gzdp_invoice_template_attachment_first'); foreach ($templates as $template) { if ($file = get_option($template)) { $file = get_attached_file($file); if (!$file) { continue; } try { $invoice = new WC_GZDP_Invoice_Preview(); $pdf = new WC_GZDP_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->set_invoice($invoice); $pdf->setTemplate($invoice->get_pdf_template()); $pdf->addPage(); } catch (Exception $e) { delete_option($template); WC_Admin_Settings::add_error(_x('Your PDF template seems be converted (version > 1.4) or compressed. Please convert (http://convert.neevia.com/pdfconvert/) your pdf file to version 1.4 or lower before uploading.', 'invoices', 'woocommerce-germanized-pro')); } } } }
/** * Manage activations */ public function pages() { // Anything you need to do before a page is loaded do_action('woocommerce_grow_pages_start'); // Get current tab $current_tab = empty($_GET['tab']) ? 'dashboard' : sanitize_title($_GET['tab']); $this->add_woocommerce_grow_pages(); // Save settings if data has been posted if (!empty($_POST)) { $this->save($current_tab); } // Add any posted messages if (!empty($_GET['wc_grow_error'])) { WC_Admin_Settings::add_error(stripslashes($_GET['wc_error'])); } if (!empty($_GET['wc_grow_message'])) { WC_Admin_Settings::add_message(stripslashes($_GET['wc_message'])); } WC_Admin_Settings::show_messages(); // Add tabs on the Grow page $tabs = apply_filters('woocommerce_grow_page_tabs_array', array()); include 'views/html-grow-page.php'; }
/** * Save settings */ public function save() { $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); if (isset($_POST['qsot_frontend_css_form_bg'])) { // Save settings $colors = array(); foreach (array('form_bg', 'form_border', 'form_action_bg', 'form_helper') as $k) { $colors[$k] = !empty($_POST['qsot_frontend_css_' . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $k]) : ''; } foreach (array('good_msg', 'bad_msg', 'remove') as $K) { foreach (array('_bg', '_border', '_text') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } foreach (array('past_calendar_item', 'calendar_item') as $K) { foreach (array('_bg', '_border', '_text', '_text_hover') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } // Check the colors. $valid_colors = true; foreach ($colors as $color) { if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { $valid_colors = false; WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'opentickets-community-edition'), $color)); break; } } if ($valid_colors) { $old_colors = get_option('woocommerce_frontend_css_colors'); $options = qsot_options::instance(); $options->{'qsot-event-frontend-colors'} = $colors; if ($old_colors != $colors) { QSOT::compile_frontend_styles(); } } } }
/** * Bulk processing for existing posts */ public function bulk_process_products() { if (!isset($_POST['woocommerce_sale-category_bulk_process'])) { return; } if (!$this->sale_category && !isset($_POST['woocommerce_sale-category_sale_category'])) { $this->errors[] = __('Please select your sale category, if you want to bulk process your existing products', 'woocommerce-sale-category'); return; } if (isset($_POST['woocommerce_sale-category_sale_category'])) { $sale_category = intval($_POST['woocommerce_sale-category_sale_category']); } else { $sale_category = $this->sale_category; } $products = wc_get_product_ids_on_sale(); if (!$products) { WC_Admin_Settings::add_error(__('No products on sale found', 'woocommerce-sale-category')); return; } foreach ($products as $post_id) { wp_set_object_terms($post_id, $sale_category, 'product_cat', true); } WC_Admin_Settings::add_message(__(count($products) . ' products processed', 'woocommerce-sale-category')); }
/** * Save settings */ public function save() { $settings = $this->get_settings(); $filtered_settings = $image_id_fields = array(); // filter out the image ids types, because WC barfs on itself over them foreach ($settings as $field) { if ('qsot-image-ids' == $field['type']) { $image_id_fields[] = $field; } else { $filtered_settings[] = $field; } } // only allow wc to save the 'safe' ones WC_Admin_Settings::save_fields($filtered_settings); // handle any image id fields foreach ($image_id_fields as $field) { // if the field did not have any values passed, then skip it if (!isset($_POST[$field['id']])) { continue; } $raw_values = $_POST[$field['id']]; // next sanitize the individual values for the field $values = array_filter(array_map('absint', $raw_values)); // allow modification of the data $values = apply_filters('woocommerce_admin_settings_sanitize_option', $values, $field, $raw_values); $values = apply_filters('woocommerce_admin_settings_sanitize_option_' . $field['id'], $values, $field, $raw_values); // update the value update_option($field['id'], $values); } if (isset($_POST['qsot_frontend_css_form_bg'])) { // Save settings $colors = array(); foreach (array('form_bg', 'form_border', 'form_action_bg', 'form_helper') as $k) { $colors[$k] = !empty($_POST['qsot_frontend_css_' . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $k]) : ''; } foreach (array('good_msg', 'bad_msg', 'remove') as $K) { foreach (array('_bg', '_border', '_text') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } foreach (array('past_calendar_item', 'calendar_item') as $K) { foreach (array('_bg', '_border', '_text', '_text_hover') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } // Check the colors. $valid_colors = true; foreach ($colors as $color) { if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { $valid_colors = false; WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'opentickets-community-edition'), $color)); break; } } if ($valid_colors) { $old_colors = get_option('woocommerce_frontend_css_colors'); $options = qsot_options::instance(); $options->{'qsot-event-frontend-colors'} = $colors; if ($old_colors != $colors) { QSOT::compile_frontend_styles(); } } } }
/** * Validate the provided credentials. */ protected function validate_active_credentials() { $settings = wc_gateway_ppec()->settings->load_settings(true); $creds = $settings->get_active_api_credentials(); $username = $creds->get_username(); $password = $creds->get_password(); if (!empty($username)) { if (empty($password)) { WC_Admin_Settings::add_error(__('Error: You must enter API password.', 'woocommerce-gateway-paypal-express-checkout')); return false; } if (is_a($creds, 'WC_Gateway_PPEC_Client_Credential_Signature') && $creds->get_signature()) { try { $payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $settings->get_environment()); if (!$payer_id) { WC_Admin_Settings::add_error(sprintf(__('Error: The %s credentials you provided are not valid. Please double-check that you entered them correctly and try again.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); return false; } } catch (PayPal_API_Exception $ex) { WC_Admin_Settings::add_error(sprintf(__('An error occurred while trying to validate your %s API credentials. Unable to verify that your API credentials are correct.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); } } elseif (is_a($creds, 'WC_Gateway_PPEC_Client_Credential_Certificate') && $creds->get_certificate()) { $cert = @openssl_x509_read($creds->get_certificate()); if (false === $cert) { WC_Admin_Settings::add_error(sprintf(__('Error: The %s API certificate is not valid.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); return false; } $cert_info = openssl_x509_parse($cert); $valid_until = $cert_info['validTo_time_t']; if ($valid_until < time()) { WC_Admin_Settings::add_error(sprintf(__('Error: The %s API certificate has expired.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); return false; } if ($cert_info['subject']['CN'] != $creds->get_username()) { WC_Admin_Settings::add_error(__('Error: The API username does not match the name in the API certificate. Make sure that you have the correct API certificate.', 'woocommerce-gateway-paypal-express-checkout')); return false; } try { $payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $settings->get_environment()); if (!$payer_id) { WC_Admin_Settings::add_error(sprintf(__('Error: The %s credentials you provided are not valid. Please double-check that you entered them correctly and try again.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); return false; } } catch (PayPal_API_Exception $ex) { WC_Admin_Settings::add_error(sprintf(__('An error occurred while trying to validate your %s API credentials. Unable to verify that your API credentials are correct.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); } } else { WC_Admin_Settings::add_error(sprintf(__('Error: You must provide a %s API signature or certificate.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout'))); return false; } $settings_array = (array) get_option('woocommerce_ppec_paypal_settings', array()); if ('yes' === $settings_array['require_billing']) { $is_account_enabled_for_billing_address = false; try { $is_account_enabled_for_billing_address = wc_gateway_ppec()->client->test_for_billing_address_enabled($creds, $settings->get_environment()); } catch (PayPal_API_Exception $ex) { $is_account_enabled_for_billing_address = false; } if (!$is_account_enabled_for_billing_address) { $settings_array['require_billing'] = 'no'; update_option('woocommerce_ppec_paypal_settings', $settings_array); WC_Admin_Settings::add_error(__('The "require billing address" option is not enabled by your account and has been disabled.', 'woocommerce-gateway-paypal-express-checkout')); } } } }
/** * Save settings */ public function save() { $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); if (isset($_POST['woocommerce_frontend_css_primary'])) { // Save settings $primary = !empty($_POST['woocommerce_frontend_css_primary']) ? wc_format_hex($_POST['woocommerce_frontend_css_primary']) : ''; $secondary = !empty($_POST['woocommerce_frontend_css_secondary']) ? wc_format_hex($_POST['woocommerce_frontend_css_secondary']) : ''; $highlight = !empty($_POST['woocommerce_frontend_css_highlight']) ? wc_format_hex($_POST['woocommerce_frontend_css_highlight']) : ''; $content_bg = !empty($_POST['woocommerce_frontend_css_content_bg']) ? wc_format_hex($_POST['woocommerce_frontend_css_content_bg']) : ''; $subtext = !empty($_POST['woocommerce_frontend_css_subtext']) ? wc_format_hex($_POST['woocommerce_frontend_css_subtext']) : ''; $colors = array('primary' => $primary, 'secondary' => $secondary, 'highlight' => $highlight, 'content_bg' => $content_bg, 'subtext' => $subtext); // Check the colors. $valid_colors = true; foreach ($colors as $color) { if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { $valid_colors = false; WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'woocommerce'), $color)); break; } } if ($valid_colors) { $old_colors = get_option('woocommerce_frontend_css_colors'); update_option('woocommerce_frontend_css_colors', $colors); if ($old_colors != $colors) { woocommerce_compile_less_styles(); } } } }
public function after_save($settings) { if (!empty($_POST['woocommerce_gzd_small_enterprise'])) { update_option('woocommerce_gzd_shipping_tax', 'no'); update_option('woocommerce_gzd_shipping_tax_force', 'no'); update_option('woocommerce_gzd_fee_tax', 'no'); update_option('woocommerce_gzd_fee_tax_force', 'no'); if (!empty($_POST['woocommerce_gzd_enable_virtual_vat'])) { update_option('woocommerce_gzd_enable_virtual_vat', 'no'); WC_Admin_Settings::add_error(__('Sorry, but the new Virtual VAT rules cannot be applied to small business.', 'woocommerce-germanized')); } } }
public function errorWebhook($e, $force_host_ssl, $url) { switch ($e->getErrorCode()) { case '6001': $msg = 'El webhook ya existe, omite este mensaje.'; return; case '6002': case '6003': $msg = 'No es posible conectarse con el servicio de webhook, verifica la URL: ' . $url; if ($force_host_ssl == true) { $this->createWebhook(true); } break; default: /* Demás errores 400 */ $msg = 'La petición no pudo ser procesada.'; break; } $error = $e->getErrorCode() . '. ' . $msg; /** * Para solo mostrar un mensaje de error en backoffice y no 2, * esto debido a que se vuelve a realizar la petición "createWebhook" con el parámetro "force_host_ssl" **/ if (!$force_host_ssl) { return; } if (function_exists('wc_add_notice')) { wc_add_notice($error, 'error'); } else { $settings = new WC_Admin_Settings(); $settings->add_error($error); } }
/** * Save global settings */ public function save() { global $current_section; if ($current_section && $this->section_save()) { update_option('wc_tfls_timestamp', time()); } else { if (!empty($_POST['wc_tfls_debug_ip']) && !filter_var($_POST['wc_tfls_debug_ip'], FILTER_VALIDATE_IP)) { WC_Admin_Settings::add_error(__('Debugging IP must be a valid IP address.', 'woocommerce-tfls')); } else { if (isset($_POST['delete_group'])) { $section_settings = (array) get_option('_oga_tfls_countries_groups'); $metakeys = array(); foreach ($_POST['delete_group'] as $value) { unset($section_settings[$value]); $metakeys[] = "'_" . $value . "_price'"; $metakeys[] = "'_" . $value . "_sale_price'"; $metakeys[] = "'_" . $value . "_variable_price'"; $metakeys[] = "'_" . $value . "_variable_sale_price'"; } update_option('_oga_tfls_countries_groups', $section_settings); //delete postmeta data global $wpdb; $wpdb->query("DELETE FROM " . $wpdb->postmeta . " WHERE meta_key in (" . implode(',', $metakeys) . ")"); } //Database geoip update if (!wp_next_scheduled('tfls_update_geoip') && isset($_POST['wc_tfls_update_geoip'])) { $update_errors = tfls_download_geoipdb(); if ($update_errors) { WC_Admin_Settings::add_error($update_errors); unset($_POST['wc_tfls_update_geoip']); } else { wp_schedule_event(time() + 2419200, '4weeks', 'tfls_update_geoip'); WC_Admin_Settings::add_message(__('GeoIP info has been updated.', 'woocommerce-tfls')); } } elseif (wp_next_scheduled('tfls_update_geoip') && !isset($_POST['wc_tfls_update_geoip'])) { wp_unschedule_event(wp_next_scheduled('tfls_update_geoip'), 'tfls_update_geoip'); } //save settings $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); update_option('wc_tfls_timestamp', time()); } } }
public function after_save($settings) { if (!empty($_POST['woocommerce_gzd_small_enterprise'])) { update_option('woocommerce_gzd_shipping_tax', 'no'); update_option('woocommerce_gzd_shipping_tax_force', 'no'); update_option('woocommerce_gzd_fee_tax', 'no'); update_option('woocommerce_gzd_fee_tax_force', 'no'); if (!empty($_POST['woocommerce_gzd_enable_virtual_vat'])) { update_option('woocommerce_gzd_enable_virtual_vat', 'no'); WC_Admin_Settings::add_error(__('Sorry, but the new Virtual VAT rules cannot be applied to small business.', 'woocommerce-germanized')); } } if ('yes' === get_option('woocommerce_gzd_enable_virtual_vat')) { // Make sure that tax based location is set to billing address if ('base' === get_option('woocommerce_tax_based_on')) { update_option('woocommerce_tax_based_on', 'billing'); } } }
public function display_errors() { foreach ($this->errors as $error) { WC_Admin_Settings::add_error($error); } }
/** * Add any settings error * * @since 1.6 */ public function add_settings_errors() { global $wpdb; // nothing doing if (!isset($_POST['woocommerce_order_number_start'])) { return; } $newvalue = $_POST['woocommerce_order_number_start']; $oldvalue = get_option('woocommerce_order_number_start'); // no change to starting order number if ((int) $newvalue === (int) $oldvalue) { return; } if ($this->is_order_number_start_invalid($newvalue)) { // bad value if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_1()) { WC_Admin_Settings::add_error(__('Order Number Start must be a number greater than or equal to 0.', self::TEXT_DOMAIN)); } else { $this->errors = __('Order Number Start must be a number greater than or equal to 0.', self::TEXT_DOMAIN); } return; } if ($this->is_order_number_start_in_use($newvalue)) { // existing order number with a greater incrementing value $post_id = (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_order_number' AND meta_value = %d", $this->get_max_order_number())); if (class_exists('WC_Order')) { $order = new WC_Order($post_id); $highest_order_number = $order->get_order_number(); } else { $highest_order_number = $post_id; } if (SV_WC_Plugin_Compatibility::is_wc_version_gte_2_1()) { WC_Admin_Settings::add_error(sprintf(__('There is an existing order (%s) with a number greater than or equal to %s. To set a new order number start please choose a higher number or permanently delete the relevant order(s).', self::TEXT_DOMAIN), $highest_order_number, (int) $newvalue)); } else { $this->errors = sprintf(__('There is an existing order (%s) with a number greater than or equal to %s. To set a new order number start please choose a higher number or permanently delete the relevant order(s).', self::TEXT_DOMAIN), $highest_order_number, (int) $newvalue); } return; } }
/** * Save section settings */ public function section_save() { global $current_section; $save = false; if (!$_POST['group_name']) { WC_Admin_Settings::add_error(__('Group name is required.', 'wc-price-based-country')); } elseif (!isset($_POST['group_countries'])) { WC_Admin_Settings::add_error(__('Add at least one country to the list.', 'wc-price-based-country')); } elseif (empty($_POST['exchange_rate']) || wc_format_decimal($_POST['exchange_rate']) == 0) { WC_Admin_Settings::add_error(__('Exchange rate must be nonzero.', 'wc-price-based-country')); } else { $section_settings = get_option('wc_price_based_country_regions', array()); $key = $current_section == 'new_group' ? sanitize_title($_POST['group_name']) : $current_section; $section_settings[$key]['name'] = $_POST['group_name']; $section_settings[$key]['countries'] = $_POST['group_countries']; $section_settings[$key]['currency'] = $_POST['group_currency']; $section_settings[$key]['exchange_rate'] = wc_format_decimal($_POST['exchange_rate']); update_option('wc_price_based_country_regions', $section_settings); if ($current_section == 'new_group') { $current_section = $key; } $save = true; } return $save; }
public function save($settings) { $generator = sanitize_title($_POST['generator']); $product = WC_germanized_pro()->get_vd_product(); // Delete hidden options $options = $this->get_options($generator . '_'); if (!empty($options)) { foreach ($options as $key => $option) { if (!isset($_POST[$generator . '_' . $key])) { delete_option($generator . '_' . $key); } } } if (!$product->is_registered()) { WC_Admin_Settings::add_error(_x('Please register WooCommerce Germanized Pro to enable the Generator.', 'generator', 'woocommerce-germanized-pro')); } $version = $this->get_version($generator); $remote = VD()->api->generator_version_check($product, $generator); if (!$remote) { return; } if (version_compare($version, $remote->version, "<")) { WC_Admin_Settings::add_error(_x('Seems like the Generator Version is not up to date. Please refresh before generating.', 'generator', 'woocommerce-germanized-pro')); } // Get data $data = array(); if (!empty($settings)) { foreach ($settings as $key => $setting) { if (isset($_POST[$setting['id']])) { $data[$setting['id']] = apply_filters('woocommerce_gzdp_generator_setting_' . $setting['id'], !is_array($_POST[$setting['id']]) ? esc_attr($_POST[$setting['id']]) : (array) $_POST[$setting['id']], $setting); } } } $result = VD()->api->generator_result_check($product, $generator, $data, $this->get_options('woocommerce_', $remote->settings)); if (!$result) { WC_Admin_Settings::add_error(_x('There seems to be a problem while generating. Is your update flatrate still active?', 'generator', 'woocommerce-germanized-pro')); } else { $this->populate_settings_observal($generator); set_transient('woocommerce_gzdp_generator_' . $generator, $result, 3 * HOUR_IN_SECONDS); set_transient('woocommerce_gzdp_generator_success_' . $generator, $result, 3 * HOUR_IN_SECONDS); } remove_action('woocommerce_gzd_after_save_section_' . $generator, array($this, 'save'), 0); }
/** * Creates an error message in the admin section * * @param string $message */ function admin_add_error($message) { $admin_settings = new WC_Admin_Settings(); $admin_settings->add_error($message, "woocommerce-mds-shipping"); }
/** * Notices. */ public static function notices() { if (isset($_GET['trashed'])) { $trashed = absint($_GET['trashed']); WC_Admin_Settings::add_message(sprintf(_n('1 webhook moved to the Trash.', '%d webhooks moved to the Trash.', $trashed, 'woocommerce'), $trashed)); } if (isset($_GET['untrashed'])) { $untrashed = absint($_GET['untrashed']); WC_Admin_Settings::add_message(sprintf(_n('1 webhook restored from the Trash.', '%d webhooks restored from the Trash.', $untrashed, 'woocommerce'), $untrashed)); } if (isset($_GET['deleted'])) { $deleted = absint($_GET['deleted']); WC_Admin_Settings::add_message(sprintf(_n('1 webhook permanently deleted.', '%d webhooks permanently deleted.', $deleted, 'woocommerce'), $deleted)); } if (isset($_GET['updated'])) { WC_Admin_Settings::add_message(__('Webhook updated successfully.', 'woocommerce')); } if (isset($_GET['created'])) { WC_Admin_Settings::add_message(__('Webhook created successfully.', 'woocommerce')); } if (isset($_GET['error'])) { WC_Admin_Settings::add_error(wc_clean($_GET['error'])); } }
/** * Helper function: add the contents of this->errors to the display queue */ public function display_errors() { foreach ($this->errors as $k => $error) { WC_Admin_Settings::add_error("Unable to save due to error: " . $error); unset($this->errors[$k]); } }