input->get('nonce'); $addon = sanitize_text_field($this->input->get('activate_addon')); if ($nonce && wp_verify_nonce($nonce,'awdr_addon_activate')) { $addons = self::getAvailableAddons(); if (isset($addons[$addon]) && !empty($addons[$addon]['plugin_file'])) { activate_plugins(array($addons[$addon]['plugin_file'])); $activated = 1; } } $redirect_url = admin_url('admin.php?page=woo_discount_rules&tab=addons'); wp_redirect(add_query_arg('addon_activated', $activated, $redirect_url)); exit; } elseif (isset($_GET['deactivate_addon'])) { $deactivated = 0; $nonce = $this->input->get('nonce'); $addon = sanitize_text_field($this->input->get('deactivate_addon')); if ($nonce && wp_verify_nonce($nonce,'awdr_addon_deactivate')) { $addons = self::getAvailableAddons(); if (isset($addons[$addon]) && !empty($addons[$addon]['plugin_file'])) { deactivate_plugins(array($addons[$addon]['plugin_file'])); $deactivated = 1; } } $redirect_url = admin_url('admin.php?page=woo_discount_rules&tab=addons'); wp_redirect(add_query_arg('addon_deactivated', $deactivated, $redirect_url)); exit; } } /** * Show up the survey form */ function setupSurveyForm() { $survey = new SurveyForm(); $survey->init('woo-discount-rules', 'Discount Rules for WooCommerce', 'woo-discount-rules'); } /** * Add settings link * @param $links * @return array */ function wdr_action_link($links) { $action_links = array( 'settings' => '' . __('Settings', 'woo-discount-rules') . '', ); return array_merge($action_links, $links); } /** * Create admin tabs and menus */ function adminTabs() { $id = $this->input->get('id', 0); $current_tab = $this->getCurrentTab(); $tabs = $this->getTabs(); $page = $this->getPageTask(); $handler = isset($tabs[$current_tab]) ? $tabs[$current_tab] : $tabs[$this->getDefaultTab()]; if ($current_tab == 'addons') { $current_addon = $this->getCurrentAddon(); $active_addons = $this->getActiveAddons(); $available_addons = $this->getAvailableAddons(); if ($current_addon) { if (isset($active_addons[$current_addon]) && is_object($active_addons[$current_addon])) { $handler = $active_addons[$current_addon]; } else { // TODO: show error message if an addon page is not found } } } $params = array( 'tabs' => $tabs, 'handler' => $handler, 'page' => $page, 'current_tab' => $current_tab); $params['on_sale_page_rebuild'] = OnSaleShortCode::getOnPageReBuildOption($id); // $load_welcome_content = $this->loadWelcomeContent(); $path = WDR_PLUGIN_PATH . 'App/Views/Admin/Menu.php'; // if($load_welcome_content === true){ // $path = WDR_PLUGIN_PATH . 'App/Views/Admin/welcome-text.php'; // } self::$template_helper->setPath($path)->setData($params)->display(); } /** * Load welcome content * */ protected function loadWelcomeContent(){ return false; } /** * get current active tab * @return mixed|string */ private function getCurrentTab() { $get_current_tab = $this->input->get('tab'); return isset($get_current_tab) ? $get_current_tab : $this->getDefaultTab(); } /** * get current active addon * @return mixed|string */ private function getCurrentAddon() { $current_addon = $this->input->get('addon'); return isset($current_addon) ? $current_addon : ''; } /** * Default tab for admin * @return string */ private function getDefaultTab() { return 'rules'; } /** * Get available tabs * @return mixed */ private function getTabs() { // return $this->tabs; $tabs = apply_filters('advanced_woo_discount_rules_page_tabs', array( 'rules' => new DiscountRules(), 'settings' => new GeneralSettings(), 'statistics' => new Statistics(), 'compatible' => new Compatible(), 'importexport' => new ImportExport(), 'help' => new Help(), 'recipe' => new Recipe(), 'addons' => new Addons(), 'recommendations' => new Recommendations() )); uasort($tabs, function ($tab1, $tab2) { $priority1 = (int)isset($tab1->priority) ? $tab1->priority : 1000; $priority2 = (int)isset($tab2->priority) ? $tab2->priority : 1000; if ($priority1 <= $priority2) { return -1; } else { return 1; } }); return $this->tabs = $tabs; } /** * Get active addons * @return mixed */ private static function getActiveAddons() { if (isset(self::$addons)) { return self::$addons; } return self::$addons = apply_filters('advanced_woo_discount_rules_page_addons', array()); } /** * Get active addons * @return mixed */ public static function getAvailableAddons() { if (isset(self::$addons_list)) { return self::$addons_list; } $addons = get_transient('awdr_addons_list'); if (empty($addons)) { $response = wp_remote_get(self::ADDONS_LIST_JSON_FILE_URL); if (!is_wp_error($response)) { $addons = (array) json_decode(wp_remote_retrieve_body($response), true); set_transient('awdr_addons_list', $addons, 24 * 60 * 60); } else { $addons = array(); } } if (!empty($addons)) { $active_plugins = apply_filters('active_plugins', get_option('active_plugins', array())); if (is_multisite()) { $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); } $available_plugins = array_keys(get_plugins()); $active_addons = self::getActiveAddons(); foreach ($addons as $slug => $addon) { $addons[$slug]['page_url'] = self::parseAddonUrl(isset($addon['page_url']) ? $addon['page_url'] : '', $slug); $addons[$slug]['settings_url'] = self::parseAddonUrl(isset($addon['settings_url']) ? $addon['settings_url'] : '', $slug); $addons[$slug]['is_active'] = isset($active_addons[$slug]) || (!empty($addon["plugin_file"]) && in_array($addon["plugin_file"], $active_plugins)); $addons[$slug]['is_installed'] = !empty($addon["plugin_file"]) && in_array($addon["plugin_file"], $available_plugins); } } return self::$addons_list = $addons; } /** * Page addon url */ private static function parseAddonUrl($url, $slug) { if (empty($url)) { return $url; } $wdr_page_url = admin_url('admin.php?page=woo_discount_rules'); $addon_page_url = admin_url('admin.php?page=woo_discount_rules&tab=addons&addon=' . $slug); return str_replace(['{admin_page}', '{wdr_page}', '{addon_page}'], [admin_url(), $wdr_page_url, $addon_page_url], $url); } /** * get page action * @return mixed|string */ private function getPageTask() { return $this->input->get('task', ''); } /** * display the admin notices if our old plugin found */ function adminNotices() { if (defined('WOO_DISCOUNT_VERSION')) { echo '
' . __("We found that your were using our old \"Woo discount rules\" plugin, Please disable it!", 'woo-discount-rules') . '
Choose what gets discount (products/categories/attributes/SKU and so on )
Note : You can also exclude products/categories.
', 'woo-discount-rules'), 'common_discount_heading' => esc_html__('Discount', 'woo-discount-rules'), 'two_column_bulk_discount_heading' => __('Discount - Read Docs', 'woo-discount-rules'), 'two_column_set_discount_heading' => __('Discount - Read Docs', 'woo-discount-rules'), 'two_column_bxgy_discount_heading' => __('Discount - Read Docs', 'woo-discount-rules'), 'two_column_bxgx_discount_heading' => __('Discount - Read Docs', 'woo-discount-rules'), 'common_discount_description' => __('Select discount type and its value (percentage/price/fixed price)
', 'woo-discount-rules'), 'bulk_filter_together_discount_description' => __('Select discount type and its value (percentage/price/fixed price)
This will count the quantities of products set in the “Filter” section.
Example: If you selected a few categories there, it will count the quantities of products in those categories added in cart. If you selected a few products in the filters section, then it will count the quantities together.
Example: Let’s say, you wanted to offer a Bulk Quantity discount for Category A and chosen Category A in the filters. So when a customer adds 1 quantity each of X, Y and Z from Category A, then the count here is 3.
Select discount type and its value (percentage/price/fixed price)
This counts the total quantity of each product / line item separately.
Example: If a customer wanted to buy 2 quantities of Product A, 3 quantities of Product B, then count will be maintained at the product level.
2 - count of Product A 3 - Count of Product BIn case of variable products, the count will be based on each variant because WooCommerce considers a variant as a product itself.
Select discount type and its value (percentage/price/fixed price)
Useful when applying discounts based on variable products and you want the quantity to be counted based on the parent product.
Example: Say, you have Product A - Small, Medium, Large. If a customer buys 2 of Product A - Small, 4 of Product A - Medium, 6 of Product A - Large, then the count will be: 6+4+2 = 12
Choose Buy Products. (products/categories/attributes/tags/sku) Example : For Buy X get Y scenarios, choose X here.
', 'woo-discount-rules'), 'bogo_buyx_getx_filter_description' => __('Choose on which products the discount should be applied (This can be products/categories/SKU)
', 'woo-discount-rules'), 'bogo_buyx_getx_discount_heading' => esc_html__('Get Discount', 'woo-discount-rules'), 'bogo_buyx_getx_discount_content' => __('Enter the min/max ranges and choose free item quantity.
Note : Enable recursive checkbox if the discounts should be applied in sequential ranges.
Example : Buy 1 get 1, Buy 2 get 2, Buy 3 get 3 and so on..
', 'woo-discount-rules'), 'bogo_buyx_gety_discount_heading' => esc_html__('Get Discount', 'woo-discount-rules'), 'bogo_buyx_gety_discount_content' => __('Choose the adjustment type to which the discount should be applied. You can choose from products/categories/all products.
Note : Enable recursive checkbox if the discounts should be applied in sequential ranges.
', 'woo-discount-rules'), 'bogo_buyx_gety_discount_content_for_product' => __('Discount will be applied only the selected products (based on mode of apply)
Note : Enable recursive checkbox if the discounts should be applied in sequential ranges.
', 'woo-discount-rules'), 'bogo_buyx_gety_discount_content_for_category' => __('Discount will be applied only the selected categories (based on mode of apply)
Note : Enable recursive checkbox if the discounts should be applied in sequential ranges.
Example ranges:
Buy 2, get 1 free (a.k.a: Buy 1 get 1 free)
Min quantity | Max quantity | Free quantity |
2 | 3 | 1 |
4 | 5 | 2 |
Discount applies on the cheapest/highest priced product IN CART.
Note : Enable recursive checkbox if the discounts should be applied in sequential ranges.
Example ranges:
Buy 2, get 1 free (a.k.a: Buy 1 get 1 free)
Min quantity | Max quantity | Free quantity |
2 | 3 | 1 |
4 | 5 | 2 |
Processing migration, please wait...
', 'woo-discount-rules'), 'processing_migration_success_message' => __('Migration completed.
', 'woo-discount-rules'), 'skip_migration_success_message' => __('Migration skipped.
', 'woo-discount-rules'), 'skip_migration_text' => __('Skipping migration, please wait...
', 'woo-discount-rules'), 'mode_variation_cumulative_example' => __('Example: Product A - Small and Product A - Medium will be counted as 2 quantity', 'woo-discount-rules'), 'filter_all_products' => __('Discount applies to all eligible products in the store', 'woo-discount-rules'), 'filter_products' => __('Choose products that get the discount using "In List". If you want to exclude a few products, choose "Not In List" and select the products you wanted to exclude from discount. (You can add multiple filters)', 'woo-discount-rules'), 'filter_Category' => __('Choose categories that get the discount using "In List". If you want to exclude a few categories, choose "Not In List" and select the categories you wanted to exclude from discount. (You can add multiple filters of same type)', 'woo-discount-rules'), 'filter_Attributes' => __(' Choose attributes that get the discount using "In List". If you want to exclude a few attributes, choose "Not In List" and select the attributes you wanted to exclude from discount. (You can add multiple filters of same type)', 'woo-discount-rules'), 'filter_Tags' => __('Choose tags that get the discount using "In List". If you want to exclude a few tags, choose "Not In List" and select the tags you wanted to exclude from discount. (You can add multiple filters of same type)', 'woo-discount-rules'), 'filter_SKUs' => __('Choose SKUs that get the discount using "In List". If you want to exclude a few SKUs, choose "Not In List" and select the SKUs you wanted to exclude from discount. (You can add multiple filters of same type)', 'woo-discount-rules'), 'filter_On_sale_products' => __('Choose whether you want to include (or exclude) products on sale (those having a sale price) for the discount ', 'woo-discount-rules'), 'filter_custom_taxonomies' => __('Discount applies to custom taxonomy', 'woo-discount-rules'), 'rebuild_on_sale_list_build_text' => __('Rebuild index', 'woo-discount-rules'), 'rebuild_on_sale_list_processing_text' => __('Processing please wait..', 'woo-discount-rules'), 'rebuild_on_sale_list_processed_text' => __('Rebuild index processed', 'woo-discount-rules'), 'rebuild_on_sale_list_error_please_select_rule' => __('Please select the rules to build index', 'woo-discount-rules'), 'invalid_file_type' => __("Invalid File. Upload : .csv File. ", 'woo-discount-rules'), 'invalid_rule_limit' => __("This rule is not running currently: Rule reached maximum usage limit", 'woo-discount-rules'), 'invalid_rule_limit_with_date_future' => __("This rule is not running currently: Start date and time is set in the future date", 'woo-discount-rules'), 'invalid_rule_limit_with_date_expire' => __("This rule is not running currently: Validity expired", 'woo-discount-rules'), 'select_state' => __("Select State", 'woo-discount-rules'), 'coupon_url_copy' => __("Copy URL", 'woo-discount-rules'), 'coupon_url_copied' => __("Copied!", 'woo-discount-rules'), 'coupon_url_success' => __("Coupon url copied!", 'woo-discount-rules'), ); } }