Changeset 3458131
- Timestamp:
- 02/10/2026 02:48:00 PM (3 months ago)
- Location:
- wc-alcohol
- Files:
-
- 4 added
- 16 edited
- 1 copied
-
tags/1.2.0 (copied) (copied from wc-alcohol/trunk)
-
tags/1.2.0/composer.json (modified) (2 diffs)
-
tags/1.2.0/includes (added)
-
tags/1.2.0/includes/class-wc-alcohol.php (added)
-
tags/1.2.0/languages/wc-alcohol-ro_RO.mo (modified) (previous)
-
tags/1.2.0/languages/wc-alcohol-ro_RO.po (modified) (5 diffs)
-
tags/1.2.0/languages/wc-alcohol-ru_RU.mo (modified) (previous)
-
tags/1.2.0/languages/wc-alcohol-ru_RU.po (modified) (5 diffs)
-
tags/1.2.0/languages/wc-alcohol.pot (modified) (2 diffs)
-
tags/1.2.0/readme.txt (modified) (4 diffs)
-
tags/1.2.0/wc-alcohol.php (modified) (2 diffs)
-
trunk/composer.json (modified) (2 diffs)
-
trunk/includes (added)
-
trunk/includes/class-wc-alcohol.php (added)
-
trunk/languages/wc-alcohol-ro_RO.mo (modified) (previous)
-
trunk/languages/wc-alcohol-ro_RO.po (modified) (5 diffs)
-
trunk/languages/wc-alcohol-ru_RU.mo (modified) (previous)
-
trunk/languages/wc-alcohol-ru_RU.po (modified) (5 diffs)
-
trunk/languages/wc-alcohol.pot (modified) (2 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/wc-alcohol.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wc-alcohol/tags/1.2.0/composer.json
r3342830 r3458131 1 1 { 2 2 "name": "alexminza/wc-alcohol", 3 "description": " AlcoholSale Restrictions for WooCommerce",3 "description": "Products Sale Restrictions for WooCommerce", 4 4 "type": "wordpress-plugin", 5 "keywords": ["WooCommerce", "alcohol", "sale", "time", "restriction"], 5 "keywords": [ 6 "WooCommerce", 7 "products", 8 "sale", 9 "time", 10 "restriction" 11 ], 6 12 "homepage": "https://github.com/alexminza/wc-alcohol", 7 13 "license": "GPL-3.0-or-later", … … 19 25 }, 20 26 "require": { 21 "php": ">=7. 0"27 "php": ">=7.2.5" 22 28 }, 23 29 "config": { 24 30 "platform": { 25 "php": "7.0" 31 "php": "7.2.5" 32 }, 33 "allow-plugins": { 34 "dealerdirect/phpcodesniffer-composer-installer": true 26 35 } 36 }, 37 "prefer-stable": true, 38 "require-dev": { 39 "woocommerce/woocommerce-sniffs": "^1.0" 27 40 } 28 41 } -
wc-alcohol/tags/1.2.0/languages/wc-alcohol-ro_RO.po
r3342830 r3458131 1 1 # Copyright (C) 2025 Alexander Minza 2 # This file is distributed under the same license as the AlcoholSale Restrictions for WooCommerce package.2 # This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Alcohol Sale Restrictions for WooCommerce 1.1.3\n"5 "Project-Id-Version: Products Sale Restrictions for WooCommerce 1.2.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n" 7 "POT-Creation-Date: 202 5-08-11 14:30+0300\n"8 "PO-Revision-Date: 202 5-08-11 14:40+0300\n"7 "POT-Creation-Date: 2026-02-07 11:53+0200\n" 8 "PO-Revision-Date: 2026-02-07 11:53+0200\n" 9 9 "Last-Translator: Alexander Minza <alex@alexminza.com>\n" 10 10 "Language-Team: \n" … … 15 15 "Plural-Forms: nplurals=3; plural=(n==1?0:(((n%100>19)||((n%100==0)&&(n!=0)))?" 16 16 "2:1));\n" 17 "X-Generator: Poedit 3. 6\n"17 "X-Generator: Poedit 3.8\n" 18 18 19 19 #. Plugin Name of the plugin 20 20 #: wc-alcohol.php 21 msgid " AlcoholSale Restrictions for WooCommerce"22 msgstr "Restricții vânzare alcoolpentru WooCommerce"21 msgid "Products Sale Restrictions for WooCommerce" 22 msgstr "Restricții vânzare produse pentru WooCommerce" 23 23 24 24 #. Description of the plugin 25 #: wc-alcohol.php wc-alcohol.php:17926 msgid " Alcohol sale limitations during restriction hours"27 msgstr "Limitări de vânzare alcool în timpul orelor de restricție"25 #: wc-alcohol.php includes/class-wc-alcohol.php:172 26 msgid "Products sale limitations during restriction hours." 27 msgstr "Limitări de vânzare produse în timpul orelor de restricție." 28 28 29 #: wc-alcohol.php:8830 msgid " Alcoholsale restrictions"31 msgstr "Restricții vânzare alcool"29 #: includes/class-wc-alcohol.php:76 30 msgid "Products sale restrictions" 31 msgstr "Restricții vânzare produse" 32 32 33 #: wc-alcohol.php:15833 #: includes/class-wc-alcohol.php:149 34 34 msgid "Settings" 35 35 msgstr "Setări" 36 36 37 #: wc-alcohol.php:18537 #: includes/class-wc-alcohol.php:178 38 38 msgid "Enable restrictions" 39 39 msgstr "Activează restricții" 40 40 41 #: wc-alcohol.php:18641 #: includes/class-wc-alcohol.php:179 42 42 msgid "Enable sale limitations during restriction hours" 43 msgstr "Activează interdicția de vânzare alcool în timpul orelor de restricție" 43 msgstr "" 44 "Activează interdicția de vânzare produse în timpul orelor de restricție" 44 45 45 #: wc-alcohol.php:19246 #: includes/class-wc-alcohol.php:185 46 47 msgid "Restriction time start" 47 48 msgstr "Început restricție" 48 49 49 #: wc-alcohol.php:19350 #: includes/class-wc-alcohol.php:186 50 51 msgid "Example: 22:00" 51 52 msgstr "Exemplu: 22:00" 52 53 53 #: wc-alcohol.php:20054 #: includes/class-wc-alcohol.php:196 54 55 msgid "Restriction time end" 55 56 msgstr "Sfârșit restricție" 56 57 57 #: wc-alcohol.php:20158 #: includes/class-wc-alcohol.php:197 58 59 msgid "Example: 09:00" 59 60 msgstr "Exemplu: 09:00" 60 61 61 #: wc-alcohol.php:20862 #: includes/class-wc-alcohol.php:207 62 63 msgid "Restricted categories" 63 64 msgstr "Categorii restricționate" 64 65 65 #: wc-alcohol.php:21466 #: includes/class-wc-alcohol.php:212 66 67 msgid "Select restricted categories" 67 68 msgstr "Selectează categoriile restricționate" 68 69 69 #: wc-alcohol.php:221 70 #: includes/class-wc-alcohol.php:218 71 msgid "Hierarchical restriction" 72 msgstr "Restricție ierarhică" 73 74 #: includes/class-wc-alcohol.php:219 75 msgid "Subcategories will inherit restrictions from their parent category." 76 msgstr "Subcategoriile vor moșteni restricții de la categoria părinte." 77 78 #: includes/class-wc-alcohol.php:227 70 79 msgid "Warning message" 71 80 msgstr "Mesaj de avertizare" 72 81 73 #: wc-alcohol.php:22282 #: includes/class-wc-alcohol.php:228 74 83 msgid "" 75 84 "Warning message displayed to the customers when trying to purchase products " … … 79 88 "din categoriile selectate în intervalul orar restricționat." 80 89 81 #: wc-alcohol.php:223 90 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 91 #: includes/class-wc-alcohol.php:230 82 92 #, php-format 83 93 msgid "" … … 88 98 "restricție, <code>%3$s</code> - Sfârșit restricție" 89 99 90 #: wc-alcohol.php:224 100 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 101 #: includes/class-wc-alcohol.php:232 91 102 #, php-format 92 103 msgid "" … … 97 108 "%3$s." 98 109 99 #: wc-alcohol.php:230110 #: includes/class-wc-alcohol.php:241 100 111 msgid "Show warning on" 101 112 msgstr "Arată avertisment pe" 102 113 103 #: wc-alcohol.php:231114 #: includes/class-wc-alcohol.php:242 104 115 msgid "Product pages" 105 116 msgstr "Pagini produse" 106 117 107 #: wc-alcohol.php:239118 #: includes/class-wc-alcohol.php:250 108 119 msgid "Category pages" 109 120 msgstr "Pagini categorii" -
wc-alcohol/tags/1.2.0/languages/wc-alcohol-ru_RU.po
r3342830 r3458131 1 1 # Copyright (C) 2025 Alexander Minza 2 # This file is distributed under the same license as the AlcoholSale Restrictions for WooCommerce package.2 # This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Alcohol Sale Restrictions for WooCommerce 1.1.3\n"5 "Project-Id-Version: Products Sale Restrictions for WooCommerce 1.2.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n" 7 "POT-Creation-Date: 202 5-08-11 14:30+0300\n"8 "PO-Revision-Date: 202 5-08-11 14:38+0300\n"7 "POT-Creation-Date: 2026-02-07 11:53+0200\n" 8 "PO-Revision-Date: 2026-02-07 11:53+0200\n" 9 9 "Last-Translator: Alexander Minza <alex@alexminza.com>\n" 10 10 "Language-Team: \n" … … 15 15 "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " 16 16 "n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 17 "X-Generator: Poedit 3. 6\n"17 "X-Generator: Poedit 3.8\n" 18 18 19 19 #. Plugin Name of the plugin 20 20 #: wc-alcohol.php 21 msgid " AlcoholSale Restrictions for WooCommerce"22 msgstr "Ограничения продажи алкоголядля WooCommerce"21 msgid "Products Sale Restrictions for WooCommerce" 22 msgstr "Ограничения продажи товаров для WooCommerce" 23 23 24 24 #. Description of the plugin 25 #: wc-alcohol.php wc-alcohol.php:17926 msgid " Alcohol sale limitations during restriction hours"27 msgstr "Запрет продажи алкоголя во время действия ограничений"25 #: wc-alcohol.php includes/class-wc-alcohol.php:172 26 msgid "Products sale limitations during restriction hours." 27 msgstr "Запрет продажи товаров во время действия ограничений." 28 28 29 #: wc-alcohol.php:8830 msgid " Alcoholsale restrictions"31 msgstr "Ограничения продажи алкоголя"29 #: includes/class-wc-alcohol.php:76 30 msgid "Products sale restrictions" 31 msgstr "Ограничения продажи товаров" 32 32 33 #: wc-alcohol.php:15833 #: includes/class-wc-alcohol.php:149 34 34 msgid "Settings" 35 35 msgstr "Настройки" 36 36 37 #: wc-alcohol.php:18537 #: includes/class-wc-alcohol.php:178 38 38 msgid "Enable restrictions" 39 39 msgstr "Включить ограничения" 40 40 41 #: wc-alcohol.php:18641 #: includes/class-wc-alcohol.php:179 42 42 msgid "Enable sale limitations during restriction hours" 43 msgstr "Включить запрет продажи алкоголяво время действия ограничений"43 msgstr "Включить запрет продажи товаров во время действия ограничений" 44 44 45 #: wc-alcohol.php:19245 #: includes/class-wc-alcohol.php:185 46 46 msgid "Restriction time start" 47 47 msgstr "Начало ограничения" 48 48 49 #: wc-alcohol.php:19349 #: includes/class-wc-alcohol.php:186 50 50 msgid "Example: 22:00" 51 51 msgstr "Пример: 22:00" 52 52 53 #: wc-alcohol.php:20053 #: includes/class-wc-alcohol.php:196 54 54 msgid "Restriction time end" 55 55 msgstr "Конец ограничения" 56 56 57 #: wc-alcohol.php:20157 #: includes/class-wc-alcohol.php:197 58 58 msgid "Example: 09:00" 59 59 msgstr "Пример: 09:00" 60 60 61 #: wc-alcohol.php:20861 #: includes/class-wc-alcohol.php:207 62 62 msgid "Restricted categories" 63 63 msgstr "Ограниченные категории" 64 64 65 #: wc-alcohol.php:21465 #: includes/class-wc-alcohol.php:212 66 66 msgid "Select restricted categories" 67 67 msgstr "Выберите ограниченные категории" 68 68 69 #: wc-alcohol.php:221 69 #: includes/class-wc-alcohol.php:218 70 msgid "Hierarchical restriction" 71 msgstr "Иерархическое ограничение" 72 73 #: includes/class-wc-alcohol.php:219 74 msgid "Subcategories will inherit restrictions from their parent category." 75 msgstr "Подкатегории унаследуют ограничения от родительской категории." 76 77 #: includes/class-wc-alcohol.php:227 70 78 msgid "Warning message" 71 79 msgstr "Предупреждающее сообщение" 72 80 73 #: wc-alcohol.php:22281 #: includes/class-wc-alcohol.php:228 74 82 msgid "" 75 83 "Warning message displayed to the customers when trying to purchase products " … … 79 87 "товары из выбранных категорий во время действия ограничений." 80 88 81 #: wc-alcohol.php:223 89 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 90 #: includes/class-wc-alcohol.php:230 82 91 #, php-format 83 92 msgid "" … … 88 97 "ограничения, <code>%3$s</code> - Конец ограничения" 89 98 90 #: wc-alcohol.php:224 99 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 100 #: includes/class-wc-alcohol.php:232 91 101 #, php-format 92 102 msgid "" … … 95 105 msgstr "Продажа товаров из категории “%1$s” запрещена с %2$s до %3$s." 96 106 97 #: wc-alcohol.php:230107 #: includes/class-wc-alcohol.php:241 98 108 msgid "Show warning on" 99 109 msgstr "Показывать предупреждение на" 100 110 101 #: wc-alcohol.php:231111 #: includes/class-wc-alcohol.php:242 102 112 msgid "Product pages" 103 113 msgstr "Страницах товаров" 104 114 105 #: wc-alcohol.php:239115 #: includes/class-wc-alcohol.php:250 106 116 msgid "Category pages" 107 117 msgstr "Страницах категорий" -
wc-alcohol/tags/1.2.0/languages/wc-alcohol.pot
r3342830 r3458131 1 # Copyright (C) 202 5Alexander Minza1 # Copyright (C) 2026 Alexander Minza 2 2 # This file is distributed under the GPLv3 or later. 3 #, fuzzy4 3 msgid "" 5 4 msgstr "" 6 "Project-Id-Version: Alcohol Sale Restrictions for WooCommerce 1.1.3\n"5 "Project-Id-Version: Products Sale Restrictions for WooCommerce 1.2.0\n" 7 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n" 8 "POT-Creation-Date: 202 5-08-11 14:30+0300\n"7 "POT-Creation-Date: 2026-02-07 11:53+0200\n" 9 8 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 10 9 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 13 12 "Content-Type: text/plain; charset=UTF-8\n" 14 13 "Content-Transfer-Encoding: 8bit\n" 15 "X-Generator: Poedit 3. 6\n"14 "X-Generator: Poedit 3.8\n" 16 15 17 16 #. Plugin Name of the plugin 18 17 #: wc-alcohol.php 19 msgid " AlcoholSale Restrictions for WooCommerce"18 msgid "Products Sale Restrictions for WooCommerce" 20 19 msgstr "" 21 20 22 21 #. Description of the plugin 23 #: wc-alcohol.php wc-alcohol.php:17924 msgid " Alcohol sale limitations during restriction hours"22 #: wc-alcohol.php includes/class-wc-alcohol.php:172 23 msgid "Products sale limitations during restriction hours." 25 24 msgstr "" 26 25 27 #: wc-alcohol.php:8828 msgid " Alcoholsale restrictions"26 #: includes/class-wc-alcohol.php:76 27 msgid "Products sale restrictions" 29 28 msgstr "" 30 29 31 #: wc-alcohol.php:15830 #: includes/class-wc-alcohol.php:149 32 31 msgid "Settings" 33 32 msgstr "" 34 33 35 #: wc-alcohol.php:18534 #: includes/class-wc-alcohol.php:178 36 35 msgid "Enable restrictions" 37 36 msgstr "" 38 37 39 #: wc-alcohol.php:18638 #: includes/class-wc-alcohol.php:179 40 39 msgid "Enable sale limitations during restriction hours" 41 40 msgstr "" 42 41 43 #: wc-alcohol.php:19242 #: includes/class-wc-alcohol.php:185 44 43 msgid "Restriction time start" 45 44 msgstr "" 46 45 47 #: wc-alcohol.php:19346 #: includes/class-wc-alcohol.php:186 48 47 msgid "Example: 22:00" 49 48 msgstr "" 50 49 51 #: wc-alcohol.php:20050 #: includes/class-wc-alcohol.php:196 52 51 msgid "Restriction time end" 53 52 msgstr "" 54 53 55 #: wc-alcohol.php:20154 #: includes/class-wc-alcohol.php:197 56 55 msgid "Example: 09:00" 57 56 msgstr "" 58 57 59 #: wc-alcohol.php:20858 #: includes/class-wc-alcohol.php:207 60 59 msgid "Restricted categories" 61 60 msgstr "" 62 61 63 #: wc-alcohol.php:21462 #: includes/class-wc-alcohol.php:212 64 63 msgid "Select restricted categories" 65 64 msgstr "" 66 65 67 #: wc-alcohol.php:221 66 #: includes/class-wc-alcohol.php:218 67 msgid "Hierarchical restriction" 68 msgstr "" 69 70 #: includes/class-wc-alcohol.php:219 71 msgid "Subcategories will inherit restrictions from their parent category." 72 msgstr "" 73 74 #: includes/class-wc-alcohol.php:227 68 75 msgid "Warning message" 69 76 msgstr "" 70 77 71 #: wc-alcohol.php:22278 #: includes/class-wc-alcohol.php:228 72 79 msgid "Warning message displayed to the customers when trying to purchase products from the selected categories during restriction hours." 73 80 msgstr "" 74 81 75 #: wc-alcohol.php:223 82 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 83 #: includes/class-wc-alcohol.php:230 76 84 #, php-format 77 85 msgid "Format: <code>%1$s</code> - Category, <code>%2$s</code> - Restriction time start, <code>%3$s</code> - Restriction time end" 78 86 msgstr "" 79 87 80 #: wc-alcohol.php:224 88 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 89 #: includes/class-wc-alcohol.php:232 81 90 #, php-format 82 91 msgid "The sale of products in the \"%1$s\" category is prohibited from %2$s to %3$s." 83 92 msgstr "" 84 93 85 #: wc-alcohol.php:23094 #: includes/class-wc-alcohol.php:241 86 95 msgid "Show warning on" 87 96 msgstr "" 88 97 89 #: wc-alcohol.php:23198 #: includes/class-wc-alcohol.php:242 90 99 msgid "Product pages" 91 100 msgstr "" 92 101 93 #: wc-alcohol.php:239102 #: includes/class-wc-alcohol.php:250 94 103 msgid "Category pages" 95 104 msgstr "" -
wc-alcohol/tags/1.2.0/readme.txt
r3342830 r3458131 1 === AlcoholSale Restrictions for WooCommerce ===1 === Products Sale Restrictions for WooCommerce === 2 2 Contributors: alexminza 3 Donate link: https://www.revolut.me/alexminza 4 Tags: WooCommerce, alcohol, sale, time, restriction 3 Tags: WooCommerce, products, sale, time, restriction 5 4 Requires at least: 4.8 6 Tested up to: 6. 87 Stable tag: 1. 1.38 Requires PHP: 7. 05 Tested up to: 6.9 6 Stable tag: 1.2.0 7 Requires PHP: 7.2.5 9 8 License: GPLv3 or later 10 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html 11 10 11 Products sale limitations during restriction hours. 12 12 13 == Description == 13 14 14 Alcohol sale limitations during legal restriction hours 15 Products sale limitations during restriction hours. 15 16 16 17 = Features = … … 26 27 = How can I configure the plugin settings? = 27 28 28 Use the *WooCommerce > Settings > Products > Alcoholsale restrictions* screen to configure the plugin.29 Use the *WooCommerce > Settings > Products > Products sale restrictions* screen to configure the plugin. 29 30 30 31 = How can I contribute to the plugin? = … … 43 44 44 45 See [wc-alcohol project releases on GitHub](https://github.com/alexminza/wc-alcohol/releases) for details. 46 47 = 1.2.0 = 48 * Code reorganization and refactoring for better maintainability 49 * Added WooCommerce compatibility declarations for Cart/Checkout blocks and product instance caching 45 50 46 51 = 1.1.3 = … … 85 90 == Upgrade Notice == 86 91 92 = 1.2.0 = 93 Code reorganization and refactoring for better maintainability. 94 87 95 = 1.1.3 = 88 96 Adjusted plugin name to comply with the [WooCommerce trademark guidelines](https://woocommerce.com/trademark-guidelines/). -
wc-alcohol/tags/1.2.0/wc-alcohol.php
r3342830 r3458131 1 1 <?php 2 2 3 /** 3 * Plugin Name: AlcoholSale Restrictions for WooCommerce4 * Description: Alcohol sale limitations during restriction hours4 * Plugin Name: Products Sale Restrictions for WooCommerce 5 * Description: Products sale limitations during restriction hours. 5 6 * Plugin URI: https://wordpress.org/plugins/wc-alcohol/ 6 * Version: 1. 1.37 * Version: 1.2.0 7 8 * Author: Alexander Minza 8 9 * Author URI: https://profiles.wordpress.org/alexminza … … 13 14 * License: GPLv3 or later 14 15 * License URI: https://www.gnu.org/licenses/gpl-3.0.html 15 * Requires PHP: 7. 016 * Requires PHP: 7.2.5 16 17 * Requires at least: 4.8 17 * Tested up to: 6. 818 * WC requires at least: 3. 219 * WC tested up to: 10. 0.418 * Tested up to: 6.9 19 * WC requires at least: 3.3 20 * WC tested up to: 10.5.0 20 21 * Requires Plugins: woocommerce 22 * 23 * @package wc-alcohol 21 24 */ 22 25 23 // Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol26 // Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol 24 27 25 if(!defined('ABSPATH')) { 26 exit; // Exit if accessed directly 28 declare(strict_types=1); 29 30 namespace AlexMinza\WC_Alcohol; 31 32 if (!defined('ABSPATH')) { 33 exit; // Exit if accessed directly 27 34 } 28 35 29 if(!class_exists(WC_Alcohol::class)): 30 class WC_Alcohol { 31 #region Constants 32 const MOD_ID = 'wc-alcohol'; 36 add_action('plugins_loaded', __NAMESPACE__ . '\alcohol_plugins_loaded_init'); 33 37 34 const MOD_SETTINGS_SECTION = self::MOD_ID; 35 const MOD_SETTINGS_PREFIX = self::MOD_SETTINGS_SECTION . '_'; 36 const MOD_SETTINGS_ENABLED = self::MOD_SETTINGS_PREFIX . 'enabled'; 37 const MOD_SETTINGS_RESTRICTION_START = self::MOD_SETTINGS_PREFIX . 'restriction_start'; 38 const MOD_SETTINGS_RESTRICTION_END = self::MOD_SETTINGS_PREFIX . 'restriction_end'; 39 const MOD_SETTINGS_CATEGORY = self::MOD_SETTINGS_PREFIX . 'category'; 40 const MOD_SETTINGS_WARNING = self::MOD_SETTINGS_PREFIX . 'warning'; 41 const MOD_SETTINGS_WARN_PRODUCT = self::MOD_SETTINGS_PREFIX . 'warn_product'; 42 const MOD_SETTINGS_WARN_CATEGORY = self::MOD_SETTINGS_PREFIX . 'warn_category'; 38 function alcohol_plugins_loaded_init() 39 { 40 if (!class_exists('WC_Settings_API')) { 41 return; 42 } 43 43 44 const RESTRICTION_START = '22:00'; 45 const RESTRICTION_END = '09:00'; 46 const RESTRICTION_CATEGORY = ''; 47 #endregion 44 require_once plugin_dir_path(__FILE__) . 'includes/class-wc-alcohol.php'; 48 45 49 /** 50 * Instance of this class. 51 * 52 * @var object 53 */ 54 protected static $instance = null; 46 WC_Alcohol::get_instance(); 55 47 56 protected $enabled, $mod_title, $categories_list, $restriction_start, $restriction_end, $restriction_start_value, $restriction_end_value; 57 protected $restricted_categories, $warning_template, $warn_product, $warn_category; 48 if (is_admin()) { 49 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(WC_Alcohol::class, 'plugin_action_links')); 50 } 51 } 58 52 59 private function __construct() { 60 $this->enabled = wc_string_to_bool(get_option(self::MOD_SETTINGS_ENABLED, 'no')); 61 $this->restriction_start = get_option(self::MOD_SETTINGS_RESTRICTION_START, self::RESTRICTION_START); 62 $this->restriction_end = get_option(self::MOD_SETTINGS_RESTRICTION_END, self::RESTRICTION_END); 63 $this->restricted_categories = get_option(self::MOD_SETTINGS_CATEGORY, self::RESTRICTION_CATEGORY); 64 $this->warning_template = get_option(self::MOD_SETTINGS_WARNING); 65 $this->warn_product = wc_string_to_bool(get_option(self::MOD_SETTINGS_WARN_PRODUCT, 'yes')); 66 $this->warn_category = wc_string_to_bool(get_option(self::MOD_SETTINGS_WARN_CATEGORY, 'yes'));53 //region Declare WooCommerce compatibility 54 add_action( 55 'before_woocommerce_init', 56 function () { 57 if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { 58 // WooCommerce HPOS compatibility 59 // https://developer.woocommerce.com/docs/features/high-performance-order-storage/recipe-book/#declaring-extension-incompatibility 60 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); 67 61 68 add_action('init', array($this, 'init')); 69 } 62 // WooCommerce Cart Checkout Blocks compatibility 63 // https://github.com/woocommerce/woocommerce/pull/36426 64 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); 70 65 71 /** 72 * Return an instance of this class. 73 * 74 * @return object A single instance of this class. 75 */ 76 public static function get_instance() { 77 // If the single instance hasn't been set, set it now. 78 if(null === self::$instance) { 79 self::$instance = new self; 80 } 81 82 return self::$instance; 83 } 84 85 public function init() { 86 load_plugin_textdomain('wc-alcohol', false, dirname(plugin_basename(__FILE__)) . '/languages'); 87 88 $this->mod_title = esc_html__('Alcohol sale restrictions', 'wc-alcohol'); 89 90 #region Init categories 91 $categories = $this->get_product_categories(); 92 $this->categories_list = wp_list_pluck($categories, 'name', 'slug'); 93 #endregion 94 95 #region Parse restriction times strings 96 $restriction_start_string = str_replace(':', '', $this->restriction_start); 97 if(is_numeric($restriction_start_string)) 98 $this->restriction_start_value = intval($restriction_start_string); 99 100 $restriction_end_string = str_replace(':', '', $this->restriction_end); 101 if(is_numeric($restriction_end_string)) 102 $this->restriction_end_value = intval($restriction_end_string); 103 #endregion 104 105 if(!$this->validate_settings()) 106 $this->enabled = false; 107 108 #region Add WooCommerce hooks 109 if(is_admin()) { 110 add_filter('woocommerce_get_sections_products', array($this, 'get_sections_products')); 111 add_filter('woocommerce_get_settings_products', array($this, 'get_settings_products'), 10, 2); 112 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_links')); 113 } 114 115 if($this->enabled) { 116 add_filter('woocommerce_is_purchasable', array($this, 'is_purchasable'), 10, 2); 117 118 if($this->warn_product) 119 add_action('woocommerce_single_product_summary', array($this, 'single_product_summary'), 20); 120 121 if($this->warn_category) 122 add_action('woocommerce_archive_description', array($this, 'archive_description'), 10); 123 } 124 #endregion 125 } 126 127 protected function validate_settings() { 128 if(empty($this->restricted_categories)) { 129 //missing restriction categories definition 130 return false; 131 } 132 133 if(self::string_empty($this->restriction_start) || self::string_empty($this->restriction_end)) { 134 //missing restriction hours 135 return false; 136 } 137 138 if(!isset($this->restriction_start_value, $this->restriction_end_value) || $this->restriction_start_value == $this->restriction_end_value) { 139 //incorrect restriction hours 140 return false; 141 } 142 143 return true; 144 } 145 146 #region Plugin settings 147 public function plugin_links($links) { 148 $settings_url = add_query_arg( 149 array( 150 'page' => 'wc-settings', 151 'tab' => 'products', 152 'section' => self::MOD_SETTINGS_SECTION 153 ), 154 admin_url('admin.php') 155 ); 156 157 $plugin_links = array( 158 sprintf('<a href="%1$s">%2$s</a>', esc_url($settings_url), esc_html__('Settings', 'wc-alcohol')) 159 ); 160 161 return array_merge($plugin_links, $links); 162 } 163 164 public function get_sections_products($sections) { 165 //https://docs.woocommerce.com/document/adding-a-section-to-a-settings-tab/ 166 $sections[self::MOD_SETTINGS_SECTION] = $this->mod_title; 167 return $sections; 168 } 169 170 public function get_settings_products($settings, $current_section) { 171 //https://github.com/woocommerce/woocommerce/blob/master/includes/admin/settings/class-wc-settings-products.php 172 if($current_section == self::MOD_SETTINGS_SECTION) { 173 $settings_mod = array(); 174 175 $settings_mod[] = array( 176 'id' => self::MOD_SETTINGS_SECTION, 177 'name' => $this->mod_title, 178 'type' => 'title', 179 'desc' => __('Alcohol sale limitations during restriction hours', 'wc-alcohol'), 180 ); 181 182 $settings_mod[] = array( 183 'id' => self::MOD_SETTINGS_ENABLED, 184 'type' => 'checkbox', 185 'name' => __('Enable restrictions', 'wc-alcohol'), 186 'desc' => __('Enable sale limitations during restriction hours', 'wc-alcohol'), 187 'default' => 'no' 188 ); 189 190 $settings_mod[] = array( 191 'id' => self::MOD_SETTINGS_RESTRICTION_START, 192 'name' => __('Restriction time start', 'wc-alcohol'), 193 'desc' => __('Example: 22:00', 'wc-alcohol'), 194 'type' => 'text', 195 'default' => self::RESTRICTION_START 196 ); 197 198 $settings_mod[] = array( 199 'id' => self::MOD_SETTINGS_RESTRICTION_END, 200 'name' => __('Restriction time end', 'wc-alcohol'), 201 'desc' => __('Example: 09:00', 'wc-alcohol'), 202 'type' => 'text', 203 'default' => self::RESTRICTION_END 204 ); 205 206 $settings_mod[] = array( 207 'id' => self::MOD_SETTINGS_CATEGORY, 208 'name' => __('Restricted categories', 'wc-alcohol'), 209 'type' => 'multiselect', 210 'class' => 'wc-enhanced-select', 211 'options' => $this->categories_list, 212 'default' => self::RESTRICTION_CATEGORY, 213 'custom_attributes' => array( 214 'data-placeholder' => esc_html__('Select restricted categories', 'wc-alcohol'), 215 ) 216 ); 217 218 $settings_mod[] = array( 219 'id' => self::MOD_SETTINGS_WARNING, 220 'type' => 'textarea', 221 'name' => __('Warning message', 'wc-alcohol'), 222 'desc_tip' => __('Warning message displayed to the customers when trying to purchase products from the selected categories during restriction hours.', 'wc-alcohol'), 223 'desc' => __('Format: <code>%1$s</code> - Category, <code>%2$s</code> - Restriction time start, <code>%3$s</code> - Restriction time end', 'wc-alcohol'), 224 'default' => esc_html__('The sale of products in the "%1$s" category is prohibited from %2$s to %3$s.', 'wc-alcohol') 225 ); 226 227 $settings_mod[] = array( 228 'id' => self::MOD_SETTINGS_WARN_PRODUCT, 229 'type' => 'checkbox', 230 'title' => __('Show warning on', 'wc-alcohol'), 231 'desc' => __('Product pages', 'wc-alcohol'), 232 'default' => 'yes', 233 'checkboxgroup' => 'start' 234 ); 235 236 $settings_mod[] = array( 237 'id' => self::MOD_SETTINGS_WARN_CATEGORY, 238 'type' => 'checkbox', 239 'desc' => __('Category pages', 'wc-alcohol'), 240 'default' => 'yes', 241 'checkboxgroup' => 'end' 242 ); 243 244 $settings_mod[] = array( 245 'type' => 'sectionend', 246 'id' => self::MOD_SETTINGS_SECTION 247 ); 248 249 return $settings_mod; 250 } else { 251 return $settings; 252 } 253 } 254 255 protected function get_product_categories() { 256 $args = array( 257 'type' => 'product', 258 'taxonomy' => 'product_cat', 259 'hierarchical' => true, 260 'hide_empty' => 0 261 ); 262 263 //https://developer.wordpress.org/reference/functions/get_categories/ 264 $categories = get_categories($args); 265 266 if(empty($categories) || is_wp_error($categories)) 267 return array(); 268 269 return $categories; 270 } 271 #endregion 272 273 protected function validate_product($product_id, $notify = true) { 274 try { 275 if($this->validate()) 276 return true; 277 278 $restricted_category = $this->get_product_restricted_category($product_id); 279 280 if(!self::string_empty($restricted_category)) { 281 if($notify) { 282 $warning_message = $this->get_warning_message($restricted_category); 283 if(!self::string_empty($warning_message)) 284 wc_add_notice($warning_message, 'error'); 285 } 286 287 return false; 288 } 289 } catch(Exception $ex) { 290 $this->log($ex, WC_Log_Levels::ERROR); 291 } 292 293 return true; 294 } 295 296 protected function get_product_restricted_category($product_id) { 297 //https://developer.wordpress.org/reference/functions/get_the_terms/ 298 $categories = get_the_terms($product_id, 'product_cat'); 299 300 if(empty($categories) || is_wp_error($categories)) 301 return null; 302 303 foreach($categories as $category) { 304 if($this->is_restricted_category($category->slug)) 305 return $category->slug; //return first found restricted product category 306 } 307 308 return null; 309 } 310 311 protected function validate_category($category) { 312 try { 313 if($this->validate()) 314 return true; 315 316 if($this->is_restricted_category($category->slug)) 317 return false; 318 } catch(Exception $ex) { 319 $this->log($ex, WC_Log_Levels::ERROR); 320 } 321 322 return true; 323 } 324 325 protected function validate() { 326 if(!$this->enabled) 327 return true; 328 329 $current_hour = intval(current_time('Hi')); 330 if($this->restriction_start_value > $this->restriction_end_value) { 331 //overnight restriction 332 if($current_hour < $this->restriction_start_value && $current_hour >= $this->restriction_end_value) 333 return true; 334 } else { 335 //intraday restrction 336 if($current_hour < $this->restriction_start_value || $current_hour >= $this->restriction_end_value) 337 return true; 338 } 339 340 return false; 341 } 342 343 #region WooCommerce hooks 344 public function is_purchasable($is_purchasable, $object) { 345 if(!$this->validate_product($object->get_id(), false)) 346 $is_purchasable = false; 347 348 return $is_purchasable; 349 } 350 351 public function single_product_summary() { 352 if(!$this->warn_product) 353 return; 354 355 global $product; 356 $product_id = $product->get_id(); 357 358 if(!$this->validate_product($product_id, false)) { 359 $restricted_category = $this->get_product_restricted_category($product_id); 360 $warning_message = $this->get_warning_message($restricted_category); 361 echo sprintf('<p class="stock out-of-stock">%1$s</p>', $warning_message); 362 } 363 } 364 365 public function archive_description() { 366 if(!$this->warn_category) 367 return; 368 369 if(is_product_category()) { 370 global $wp_query; 371 $category = $wp_query->get_queried_object(); 372 373 if(empty($category) || is_wp_error($category)) 374 return; 375 376 if(!$this->validate_category($category)) { 377 $warning_message = $this->get_warning_message($category->slug); 378 if(!self::string_empty($warning_message)) { 379 echo sprintf('<div class="term-description">%1$s</div>', wc_format_content($warning_message)); 380 //wc_add_notice($warning_message, 'error'); 381 } 382 } 383 } 384 } 385 #endregion 386 387 protected function is_restricted_category($category_slug) { 388 return in_array($category_slug, $this->restricted_categories, true); 389 } 390 391 protected function get_warning_message($category_slug) { 392 $category_name = $this->categories_list[$category_slug]; 393 $warning_message = do_shortcode(wp_kses_post(sprintf($this->warning_template, $category_name, $this->restriction_start, $this->restriction_end))); 394 395 return $warning_message; 396 } 397 398 protected function log($message, $level = WC_Log_Levels::DEBUG) { 399 //https://woocommerce.wordpress.com/2017/01/26/improved-logging-in-woocommerce-2-7/ 400 //https://stackoverflow.com/questions/1423157/print-php-call-stack 401 $logger = wc_get_logger(); 402 $log_context = array('source' => self::MOD_ID); 403 $logger->log($level, $message, $log_context); 404 } 405 406 protected static function string_empty($string) { 407 return is_null($string) || strlen($string) === 0; 408 } 409 } 410 411 //https://docs.woocommerce.com/document/query-whether-woocommerce-is-activated/ 412 if(!class_exists('WooCommerce')) { 413 add_action('plugins_loaded', array(WC_Alcohol::class, 'get_instance')); 414 } 415 endif; 416 417 #region WooCommerce HPOS compatibility 418 //https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility 419 add_action('before_woocommerce_init', function() { 420 if(class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { 421 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); 422 } 423 }); 424 #endregion 66 // WooCommerce Product Object Caching compatibility 67 // https://developer.woocommerce.com/2026/01/19/experimental-product-object-caching-in-woocommerce-10-5/ 68 // https://github.com/woocommerce/woocommerce/pull/62041 69 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('product_instance_caching', __FILE__, true); 70 } 71 } 72 ); 73 //endregion -
wc-alcohol/trunk/composer.json
r3342830 r3458131 1 1 { 2 2 "name": "alexminza/wc-alcohol", 3 "description": " AlcoholSale Restrictions for WooCommerce",3 "description": "Products Sale Restrictions for WooCommerce", 4 4 "type": "wordpress-plugin", 5 "keywords": ["WooCommerce", "alcohol", "sale", "time", "restriction"], 5 "keywords": [ 6 "WooCommerce", 7 "products", 8 "sale", 9 "time", 10 "restriction" 11 ], 6 12 "homepage": "https://github.com/alexminza/wc-alcohol", 7 13 "license": "GPL-3.0-or-later", … … 19 25 }, 20 26 "require": { 21 "php": ">=7. 0"27 "php": ">=7.2.5" 22 28 }, 23 29 "config": { 24 30 "platform": { 25 "php": "7.0" 31 "php": "7.2.5" 32 }, 33 "allow-plugins": { 34 "dealerdirect/phpcodesniffer-composer-installer": true 26 35 } 36 }, 37 "prefer-stable": true, 38 "require-dev": { 39 "woocommerce/woocommerce-sniffs": "^1.0" 27 40 } 28 41 } -
wc-alcohol/trunk/languages/wc-alcohol-ro_RO.po
r3342830 r3458131 1 1 # Copyright (C) 2025 Alexander Minza 2 # This file is distributed under the same license as the AlcoholSale Restrictions for WooCommerce package.2 # This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Alcohol Sale Restrictions for WooCommerce 1.1.3\n"5 "Project-Id-Version: Products Sale Restrictions for WooCommerce 1.2.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n" 7 "POT-Creation-Date: 202 5-08-11 14:30+0300\n"8 "PO-Revision-Date: 202 5-08-11 14:40+0300\n"7 "POT-Creation-Date: 2026-02-07 11:53+0200\n" 8 "PO-Revision-Date: 2026-02-07 11:53+0200\n" 9 9 "Last-Translator: Alexander Minza <alex@alexminza.com>\n" 10 10 "Language-Team: \n" … … 15 15 "Plural-Forms: nplurals=3; plural=(n==1?0:(((n%100>19)||((n%100==0)&&(n!=0)))?" 16 16 "2:1));\n" 17 "X-Generator: Poedit 3. 6\n"17 "X-Generator: Poedit 3.8\n" 18 18 19 19 #. Plugin Name of the plugin 20 20 #: wc-alcohol.php 21 msgid " AlcoholSale Restrictions for WooCommerce"22 msgstr "Restricții vânzare alcoolpentru WooCommerce"21 msgid "Products Sale Restrictions for WooCommerce" 22 msgstr "Restricții vânzare produse pentru WooCommerce" 23 23 24 24 #. Description of the plugin 25 #: wc-alcohol.php wc-alcohol.php:17926 msgid " Alcohol sale limitations during restriction hours"27 msgstr "Limitări de vânzare alcool în timpul orelor de restricție"25 #: wc-alcohol.php includes/class-wc-alcohol.php:172 26 msgid "Products sale limitations during restriction hours." 27 msgstr "Limitări de vânzare produse în timpul orelor de restricție." 28 28 29 #: wc-alcohol.php:8830 msgid " Alcoholsale restrictions"31 msgstr "Restricții vânzare alcool"29 #: includes/class-wc-alcohol.php:76 30 msgid "Products sale restrictions" 31 msgstr "Restricții vânzare produse" 32 32 33 #: wc-alcohol.php:15833 #: includes/class-wc-alcohol.php:149 34 34 msgid "Settings" 35 35 msgstr "Setări" 36 36 37 #: wc-alcohol.php:18537 #: includes/class-wc-alcohol.php:178 38 38 msgid "Enable restrictions" 39 39 msgstr "Activează restricții" 40 40 41 #: wc-alcohol.php:18641 #: includes/class-wc-alcohol.php:179 42 42 msgid "Enable sale limitations during restriction hours" 43 msgstr "Activează interdicția de vânzare alcool în timpul orelor de restricție" 43 msgstr "" 44 "Activează interdicția de vânzare produse în timpul orelor de restricție" 44 45 45 #: wc-alcohol.php:19246 #: includes/class-wc-alcohol.php:185 46 47 msgid "Restriction time start" 47 48 msgstr "Început restricție" 48 49 49 #: wc-alcohol.php:19350 #: includes/class-wc-alcohol.php:186 50 51 msgid "Example: 22:00" 51 52 msgstr "Exemplu: 22:00" 52 53 53 #: wc-alcohol.php:20054 #: includes/class-wc-alcohol.php:196 54 55 msgid "Restriction time end" 55 56 msgstr "Sfârșit restricție" 56 57 57 #: wc-alcohol.php:20158 #: includes/class-wc-alcohol.php:197 58 59 msgid "Example: 09:00" 59 60 msgstr "Exemplu: 09:00" 60 61 61 #: wc-alcohol.php:20862 #: includes/class-wc-alcohol.php:207 62 63 msgid "Restricted categories" 63 64 msgstr "Categorii restricționate" 64 65 65 #: wc-alcohol.php:21466 #: includes/class-wc-alcohol.php:212 66 67 msgid "Select restricted categories" 67 68 msgstr "Selectează categoriile restricționate" 68 69 69 #: wc-alcohol.php:221 70 #: includes/class-wc-alcohol.php:218 71 msgid "Hierarchical restriction" 72 msgstr "Restricție ierarhică" 73 74 #: includes/class-wc-alcohol.php:219 75 msgid "Subcategories will inherit restrictions from their parent category." 76 msgstr "Subcategoriile vor moșteni restricții de la categoria părinte." 77 78 #: includes/class-wc-alcohol.php:227 70 79 msgid "Warning message" 71 80 msgstr "Mesaj de avertizare" 72 81 73 #: wc-alcohol.php:22282 #: includes/class-wc-alcohol.php:228 74 83 msgid "" 75 84 "Warning message displayed to the customers when trying to purchase products " … … 79 88 "din categoriile selectate în intervalul orar restricționat." 80 89 81 #: wc-alcohol.php:223 90 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 91 #: includes/class-wc-alcohol.php:230 82 92 #, php-format 83 93 msgid "" … … 88 98 "restricție, <code>%3$s</code> - Sfârșit restricție" 89 99 90 #: wc-alcohol.php:224 100 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 101 #: includes/class-wc-alcohol.php:232 91 102 #, php-format 92 103 msgid "" … … 97 108 "%3$s." 98 109 99 #: wc-alcohol.php:230110 #: includes/class-wc-alcohol.php:241 100 111 msgid "Show warning on" 101 112 msgstr "Arată avertisment pe" 102 113 103 #: wc-alcohol.php:231114 #: includes/class-wc-alcohol.php:242 104 115 msgid "Product pages" 105 116 msgstr "Pagini produse" 106 117 107 #: wc-alcohol.php:239118 #: includes/class-wc-alcohol.php:250 108 119 msgid "Category pages" 109 120 msgstr "Pagini categorii" -
wc-alcohol/trunk/languages/wc-alcohol-ru_RU.po
r3342830 r3458131 1 1 # Copyright (C) 2025 Alexander Minza 2 # This file is distributed under the same license as the AlcoholSale Restrictions for WooCommerce package.2 # This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Alcohol Sale Restrictions for WooCommerce 1.1.3\n"5 "Project-Id-Version: Products Sale Restrictions for WooCommerce 1.2.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n" 7 "POT-Creation-Date: 202 5-08-11 14:30+0300\n"8 "PO-Revision-Date: 202 5-08-11 14:38+0300\n"7 "POT-Creation-Date: 2026-02-07 11:53+0200\n" 8 "PO-Revision-Date: 2026-02-07 11:53+0200\n" 9 9 "Last-Translator: Alexander Minza <alex@alexminza.com>\n" 10 10 "Language-Team: \n" … … 15 15 "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " 16 16 "n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 17 "X-Generator: Poedit 3. 6\n"17 "X-Generator: Poedit 3.8\n" 18 18 19 19 #. Plugin Name of the plugin 20 20 #: wc-alcohol.php 21 msgid " AlcoholSale Restrictions for WooCommerce"22 msgstr "Ограничения продажи алкоголядля WooCommerce"21 msgid "Products Sale Restrictions for WooCommerce" 22 msgstr "Ограничения продажи товаров для WooCommerce" 23 23 24 24 #. Description of the plugin 25 #: wc-alcohol.php wc-alcohol.php:17926 msgid " Alcohol sale limitations during restriction hours"27 msgstr "Запрет продажи алкоголя во время действия ограничений"25 #: wc-alcohol.php includes/class-wc-alcohol.php:172 26 msgid "Products sale limitations during restriction hours." 27 msgstr "Запрет продажи товаров во время действия ограничений." 28 28 29 #: wc-alcohol.php:8830 msgid " Alcoholsale restrictions"31 msgstr "Ограничения продажи алкоголя"29 #: includes/class-wc-alcohol.php:76 30 msgid "Products sale restrictions" 31 msgstr "Ограничения продажи товаров" 32 32 33 #: wc-alcohol.php:15833 #: includes/class-wc-alcohol.php:149 34 34 msgid "Settings" 35 35 msgstr "Настройки" 36 36 37 #: wc-alcohol.php:18537 #: includes/class-wc-alcohol.php:178 38 38 msgid "Enable restrictions" 39 39 msgstr "Включить ограничения" 40 40 41 #: wc-alcohol.php:18641 #: includes/class-wc-alcohol.php:179 42 42 msgid "Enable sale limitations during restriction hours" 43 msgstr "Включить запрет продажи алкоголяво время действия ограничений"43 msgstr "Включить запрет продажи товаров во время действия ограничений" 44 44 45 #: wc-alcohol.php:19245 #: includes/class-wc-alcohol.php:185 46 46 msgid "Restriction time start" 47 47 msgstr "Начало ограничения" 48 48 49 #: wc-alcohol.php:19349 #: includes/class-wc-alcohol.php:186 50 50 msgid "Example: 22:00" 51 51 msgstr "Пример: 22:00" 52 52 53 #: wc-alcohol.php:20053 #: includes/class-wc-alcohol.php:196 54 54 msgid "Restriction time end" 55 55 msgstr "Конец ограничения" 56 56 57 #: wc-alcohol.php:20157 #: includes/class-wc-alcohol.php:197 58 58 msgid "Example: 09:00" 59 59 msgstr "Пример: 09:00" 60 60 61 #: wc-alcohol.php:20861 #: includes/class-wc-alcohol.php:207 62 62 msgid "Restricted categories" 63 63 msgstr "Ограниченные категории" 64 64 65 #: wc-alcohol.php:21465 #: includes/class-wc-alcohol.php:212 66 66 msgid "Select restricted categories" 67 67 msgstr "Выберите ограниченные категории" 68 68 69 #: wc-alcohol.php:221 69 #: includes/class-wc-alcohol.php:218 70 msgid "Hierarchical restriction" 71 msgstr "Иерархическое ограничение" 72 73 #: includes/class-wc-alcohol.php:219 74 msgid "Subcategories will inherit restrictions from their parent category." 75 msgstr "Подкатегории унаследуют ограничения от родительской категории." 76 77 #: includes/class-wc-alcohol.php:227 70 78 msgid "Warning message" 71 79 msgstr "Предупреждающее сообщение" 72 80 73 #: wc-alcohol.php:22281 #: includes/class-wc-alcohol.php:228 74 82 msgid "" 75 83 "Warning message displayed to the customers when trying to purchase products " … … 79 87 "товары из выбранных категорий во время действия ограничений." 80 88 81 #: wc-alcohol.php:223 89 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 90 #: includes/class-wc-alcohol.php:230 82 91 #, php-format 83 92 msgid "" … … 88 97 "ограничения, <code>%3$s</code> - Конец ограничения" 89 98 90 #: wc-alcohol.php:224 99 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 100 #: includes/class-wc-alcohol.php:232 91 101 #, php-format 92 102 msgid "" … … 95 105 msgstr "Продажа товаров из категории “%1$s” запрещена с %2$s до %3$s." 96 106 97 #: wc-alcohol.php:230107 #: includes/class-wc-alcohol.php:241 98 108 msgid "Show warning on" 99 109 msgstr "Показывать предупреждение на" 100 110 101 #: wc-alcohol.php:231111 #: includes/class-wc-alcohol.php:242 102 112 msgid "Product pages" 103 113 msgstr "Страницах товаров" 104 114 105 #: wc-alcohol.php:239115 #: includes/class-wc-alcohol.php:250 106 116 msgid "Category pages" 107 117 msgstr "Страницах категорий" -
wc-alcohol/trunk/languages/wc-alcohol.pot
r3342830 r3458131 1 # Copyright (C) 202 5Alexander Minza1 # Copyright (C) 2026 Alexander Minza 2 2 # This file is distributed under the GPLv3 or later. 3 #, fuzzy4 3 msgid "" 5 4 msgstr "" 6 "Project-Id-Version: Alcohol Sale Restrictions for WooCommerce 1.1.3\n"5 "Project-Id-Version: Products Sale Restrictions for WooCommerce 1.2.0\n" 7 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n" 8 "POT-Creation-Date: 202 5-08-11 14:30+0300\n"7 "POT-Creation-Date: 2026-02-07 11:53+0200\n" 9 8 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 10 9 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 13 12 "Content-Type: text/plain; charset=UTF-8\n" 14 13 "Content-Transfer-Encoding: 8bit\n" 15 "X-Generator: Poedit 3. 6\n"14 "X-Generator: Poedit 3.8\n" 16 15 17 16 #. Plugin Name of the plugin 18 17 #: wc-alcohol.php 19 msgid " AlcoholSale Restrictions for WooCommerce"18 msgid "Products Sale Restrictions for WooCommerce" 20 19 msgstr "" 21 20 22 21 #. Description of the plugin 23 #: wc-alcohol.php wc-alcohol.php:17924 msgid " Alcohol sale limitations during restriction hours"22 #: wc-alcohol.php includes/class-wc-alcohol.php:172 23 msgid "Products sale limitations during restriction hours." 25 24 msgstr "" 26 25 27 #: wc-alcohol.php:8828 msgid " Alcoholsale restrictions"26 #: includes/class-wc-alcohol.php:76 27 msgid "Products sale restrictions" 29 28 msgstr "" 30 29 31 #: wc-alcohol.php:15830 #: includes/class-wc-alcohol.php:149 32 31 msgid "Settings" 33 32 msgstr "" 34 33 35 #: wc-alcohol.php:18534 #: includes/class-wc-alcohol.php:178 36 35 msgid "Enable restrictions" 37 36 msgstr "" 38 37 39 #: wc-alcohol.php:18638 #: includes/class-wc-alcohol.php:179 40 39 msgid "Enable sale limitations during restriction hours" 41 40 msgstr "" 42 41 43 #: wc-alcohol.php:19242 #: includes/class-wc-alcohol.php:185 44 43 msgid "Restriction time start" 45 44 msgstr "" 46 45 47 #: wc-alcohol.php:19346 #: includes/class-wc-alcohol.php:186 48 47 msgid "Example: 22:00" 49 48 msgstr "" 50 49 51 #: wc-alcohol.php:20050 #: includes/class-wc-alcohol.php:196 52 51 msgid "Restriction time end" 53 52 msgstr "" 54 53 55 #: wc-alcohol.php:20154 #: includes/class-wc-alcohol.php:197 56 55 msgid "Example: 09:00" 57 56 msgstr "" 58 57 59 #: wc-alcohol.php:20858 #: includes/class-wc-alcohol.php:207 60 59 msgid "Restricted categories" 61 60 msgstr "" 62 61 63 #: wc-alcohol.php:21462 #: includes/class-wc-alcohol.php:212 64 63 msgid "Select restricted categories" 65 64 msgstr "" 66 65 67 #: wc-alcohol.php:221 66 #: includes/class-wc-alcohol.php:218 67 msgid "Hierarchical restriction" 68 msgstr "" 69 70 #: includes/class-wc-alcohol.php:219 71 msgid "Subcategories will inherit restrictions from their parent category." 72 msgstr "" 73 74 #: includes/class-wc-alcohol.php:227 68 75 msgid "Warning message" 69 76 msgstr "" 70 77 71 #: wc-alcohol.php:22278 #: includes/class-wc-alcohol.php:228 72 79 msgid "Warning message displayed to the customers when trying to purchase products from the selected categories during restriction hours." 73 80 msgstr "" 74 81 75 #: wc-alcohol.php:223 82 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 83 #: includes/class-wc-alcohol.php:230 76 84 #, php-format 77 85 msgid "Format: <code>%1$s</code> - Category, <code>%2$s</code> - Restriction time start, <code>%3$s</code> - Restriction time end" 78 86 msgstr "" 79 87 80 #: wc-alcohol.php:224 88 #. translators: 1: Category name, 2: Restriction time start, 3: Restriction time end 89 #: includes/class-wc-alcohol.php:232 81 90 #, php-format 82 91 msgid "The sale of products in the \"%1$s\" category is prohibited from %2$s to %3$s." 83 92 msgstr "" 84 93 85 #: wc-alcohol.php:23094 #: includes/class-wc-alcohol.php:241 86 95 msgid "Show warning on" 87 96 msgstr "" 88 97 89 #: wc-alcohol.php:23198 #: includes/class-wc-alcohol.php:242 90 99 msgid "Product pages" 91 100 msgstr "" 92 101 93 #: wc-alcohol.php:239102 #: includes/class-wc-alcohol.php:250 94 103 msgid "Category pages" 95 104 msgstr "" -
wc-alcohol/trunk/readme.txt
r3342830 r3458131 1 === AlcoholSale Restrictions for WooCommerce ===1 === Products Sale Restrictions for WooCommerce === 2 2 Contributors: alexminza 3 Donate link: https://www.revolut.me/alexminza 4 Tags: WooCommerce, alcohol, sale, time, restriction 3 Tags: WooCommerce, products, sale, time, restriction 5 4 Requires at least: 4.8 6 Tested up to: 6. 87 Stable tag: 1. 1.38 Requires PHP: 7. 05 Tested up to: 6.9 6 Stable tag: 1.2.0 7 Requires PHP: 7.2.5 9 8 License: GPLv3 or later 10 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html 11 10 11 Products sale limitations during restriction hours. 12 12 13 == Description == 13 14 14 Alcohol sale limitations during legal restriction hours 15 Products sale limitations during restriction hours. 15 16 16 17 = Features = … … 26 27 = How can I configure the plugin settings? = 27 28 28 Use the *WooCommerce > Settings > Products > Alcoholsale restrictions* screen to configure the plugin.29 Use the *WooCommerce > Settings > Products > Products sale restrictions* screen to configure the plugin. 29 30 30 31 = How can I contribute to the plugin? = … … 43 44 44 45 See [wc-alcohol project releases on GitHub](https://github.com/alexminza/wc-alcohol/releases) for details. 46 47 = 1.2.0 = 48 * Code reorganization and refactoring for better maintainability 49 * Added WooCommerce compatibility declarations for Cart/Checkout blocks and product instance caching 45 50 46 51 = 1.1.3 = … … 85 90 == Upgrade Notice == 86 91 92 = 1.2.0 = 93 Code reorganization and refactoring for better maintainability. 94 87 95 = 1.1.3 = 88 96 Adjusted plugin name to comply with the [WooCommerce trademark guidelines](https://woocommerce.com/trademark-guidelines/). -
wc-alcohol/trunk/wc-alcohol.php
r3342830 r3458131 1 1 <?php 2 2 3 /** 3 * Plugin Name: AlcoholSale Restrictions for WooCommerce4 * Description: Alcohol sale limitations during restriction hours4 * Plugin Name: Products Sale Restrictions for WooCommerce 5 * Description: Products sale limitations during restriction hours. 5 6 * Plugin URI: https://wordpress.org/plugins/wc-alcohol/ 6 * Version: 1. 1.37 * Version: 1.2.0 7 8 * Author: Alexander Minza 8 9 * Author URI: https://profiles.wordpress.org/alexminza … … 13 14 * License: GPLv3 or later 14 15 * License URI: https://www.gnu.org/licenses/gpl-3.0.html 15 * Requires PHP: 7. 016 * Requires PHP: 7.2.5 16 17 * Requires at least: 4.8 17 * Tested up to: 6. 818 * WC requires at least: 3. 219 * WC tested up to: 10. 0.418 * Tested up to: 6.9 19 * WC requires at least: 3.3 20 * WC tested up to: 10.5.0 20 21 * Requires Plugins: woocommerce 22 * 23 * @package wc-alcohol 21 24 */ 22 25 23 // Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol26 // Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol 24 27 25 if(!defined('ABSPATH')) { 26 exit; // Exit if accessed directly 28 declare(strict_types=1); 29 30 namespace AlexMinza\WC_Alcohol; 31 32 if (!defined('ABSPATH')) { 33 exit; // Exit if accessed directly 27 34 } 28 35 29 if(!class_exists(WC_Alcohol::class)): 30 class WC_Alcohol { 31 #region Constants 32 const MOD_ID = 'wc-alcohol'; 36 add_action('plugins_loaded', __NAMESPACE__ . '\alcohol_plugins_loaded_init'); 33 37 34 const MOD_SETTINGS_SECTION = self::MOD_ID; 35 const MOD_SETTINGS_PREFIX = self::MOD_SETTINGS_SECTION . '_'; 36 const MOD_SETTINGS_ENABLED = self::MOD_SETTINGS_PREFIX . 'enabled'; 37 const MOD_SETTINGS_RESTRICTION_START = self::MOD_SETTINGS_PREFIX . 'restriction_start'; 38 const MOD_SETTINGS_RESTRICTION_END = self::MOD_SETTINGS_PREFIX . 'restriction_end'; 39 const MOD_SETTINGS_CATEGORY = self::MOD_SETTINGS_PREFIX . 'category'; 40 const MOD_SETTINGS_WARNING = self::MOD_SETTINGS_PREFIX . 'warning'; 41 const MOD_SETTINGS_WARN_PRODUCT = self::MOD_SETTINGS_PREFIX . 'warn_product'; 42 const MOD_SETTINGS_WARN_CATEGORY = self::MOD_SETTINGS_PREFIX . 'warn_category'; 38 function alcohol_plugins_loaded_init() 39 { 40 if (!class_exists('WC_Settings_API')) { 41 return; 42 } 43 43 44 const RESTRICTION_START = '22:00'; 45 const RESTRICTION_END = '09:00'; 46 const RESTRICTION_CATEGORY = ''; 47 #endregion 44 require_once plugin_dir_path(__FILE__) . 'includes/class-wc-alcohol.php'; 48 45 49 /** 50 * Instance of this class. 51 * 52 * @var object 53 */ 54 protected static $instance = null; 46 WC_Alcohol::get_instance(); 55 47 56 protected $enabled, $mod_title, $categories_list, $restriction_start, $restriction_end, $restriction_start_value, $restriction_end_value; 57 protected $restricted_categories, $warning_template, $warn_product, $warn_category; 48 if (is_admin()) { 49 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(WC_Alcohol::class, 'plugin_action_links')); 50 } 51 } 58 52 59 private function __construct() { 60 $this->enabled = wc_string_to_bool(get_option(self::MOD_SETTINGS_ENABLED, 'no')); 61 $this->restriction_start = get_option(self::MOD_SETTINGS_RESTRICTION_START, self::RESTRICTION_START); 62 $this->restriction_end = get_option(self::MOD_SETTINGS_RESTRICTION_END, self::RESTRICTION_END); 63 $this->restricted_categories = get_option(self::MOD_SETTINGS_CATEGORY, self::RESTRICTION_CATEGORY); 64 $this->warning_template = get_option(self::MOD_SETTINGS_WARNING); 65 $this->warn_product = wc_string_to_bool(get_option(self::MOD_SETTINGS_WARN_PRODUCT, 'yes')); 66 $this->warn_category = wc_string_to_bool(get_option(self::MOD_SETTINGS_WARN_CATEGORY, 'yes'));53 //region Declare WooCommerce compatibility 54 add_action( 55 'before_woocommerce_init', 56 function () { 57 if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { 58 // WooCommerce HPOS compatibility 59 // https://developer.woocommerce.com/docs/features/high-performance-order-storage/recipe-book/#declaring-extension-incompatibility 60 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); 67 61 68 add_action('init', array($this, 'init')); 69 } 62 // WooCommerce Cart Checkout Blocks compatibility 63 // https://github.com/woocommerce/woocommerce/pull/36426 64 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); 70 65 71 /** 72 * Return an instance of this class. 73 * 74 * @return object A single instance of this class. 75 */ 76 public static function get_instance() { 77 // If the single instance hasn't been set, set it now. 78 if(null === self::$instance) { 79 self::$instance = new self; 80 } 81 82 return self::$instance; 83 } 84 85 public function init() { 86 load_plugin_textdomain('wc-alcohol', false, dirname(plugin_basename(__FILE__)) . '/languages'); 87 88 $this->mod_title = esc_html__('Alcohol sale restrictions', 'wc-alcohol'); 89 90 #region Init categories 91 $categories = $this->get_product_categories(); 92 $this->categories_list = wp_list_pluck($categories, 'name', 'slug'); 93 #endregion 94 95 #region Parse restriction times strings 96 $restriction_start_string = str_replace(':', '', $this->restriction_start); 97 if(is_numeric($restriction_start_string)) 98 $this->restriction_start_value = intval($restriction_start_string); 99 100 $restriction_end_string = str_replace(':', '', $this->restriction_end); 101 if(is_numeric($restriction_end_string)) 102 $this->restriction_end_value = intval($restriction_end_string); 103 #endregion 104 105 if(!$this->validate_settings()) 106 $this->enabled = false; 107 108 #region Add WooCommerce hooks 109 if(is_admin()) { 110 add_filter('woocommerce_get_sections_products', array($this, 'get_sections_products')); 111 add_filter('woocommerce_get_settings_products', array($this, 'get_settings_products'), 10, 2); 112 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_links')); 113 } 114 115 if($this->enabled) { 116 add_filter('woocommerce_is_purchasable', array($this, 'is_purchasable'), 10, 2); 117 118 if($this->warn_product) 119 add_action('woocommerce_single_product_summary', array($this, 'single_product_summary'), 20); 120 121 if($this->warn_category) 122 add_action('woocommerce_archive_description', array($this, 'archive_description'), 10); 123 } 124 #endregion 125 } 126 127 protected function validate_settings() { 128 if(empty($this->restricted_categories)) { 129 //missing restriction categories definition 130 return false; 131 } 132 133 if(self::string_empty($this->restriction_start) || self::string_empty($this->restriction_end)) { 134 //missing restriction hours 135 return false; 136 } 137 138 if(!isset($this->restriction_start_value, $this->restriction_end_value) || $this->restriction_start_value == $this->restriction_end_value) { 139 //incorrect restriction hours 140 return false; 141 } 142 143 return true; 144 } 145 146 #region Plugin settings 147 public function plugin_links($links) { 148 $settings_url = add_query_arg( 149 array( 150 'page' => 'wc-settings', 151 'tab' => 'products', 152 'section' => self::MOD_SETTINGS_SECTION 153 ), 154 admin_url('admin.php') 155 ); 156 157 $plugin_links = array( 158 sprintf('<a href="%1$s">%2$s</a>', esc_url($settings_url), esc_html__('Settings', 'wc-alcohol')) 159 ); 160 161 return array_merge($plugin_links, $links); 162 } 163 164 public function get_sections_products($sections) { 165 //https://docs.woocommerce.com/document/adding-a-section-to-a-settings-tab/ 166 $sections[self::MOD_SETTINGS_SECTION] = $this->mod_title; 167 return $sections; 168 } 169 170 public function get_settings_products($settings, $current_section) { 171 //https://github.com/woocommerce/woocommerce/blob/master/includes/admin/settings/class-wc-settings-products.php 172 if($current_section == self::MOD_SETTINGS_SECTION) { 173 $settings_mod = array(); 174 175 $settings_mod[] = array( 176 'id' => self::MOD_SETTINGS_SECTION, 177 'name' => $this->mod_title, 178 'type' => 'title', 179 'desc' => __('Alcohol sale limitations during restriction hours', 'wc-alcohol'), 180 ); 181 182 $settings_mod[] = array( 183 'id' => self::MOD_SETTINGS_ENABLED, 184 'type' => 'checkbox', 185 'name' => __('Enable restrictions', 'wc-alcohol'), 186 'desc' => __('Enable sale limitations during restriction hours', 'wc-alcohol'), 187 'default' => 'no' 188 ); 189 190 $settings_mod[] = array( 191 'id' => self::MOD_SETTINGS_RESTRICTION_START, 192 'name' => __('Restriction time start', 'wc-alcohol'), 193 'desc' => __('Example: 22:00', 'wc-alcohol'), 194 'type' => 'text', 195 'default' => self::RESTRICTION_START 196 ); 197 198 $settings_mod[] = array( 199 'id' => self::MOD_SETTINGS_RESTRICTION_END, 200 'name' => __('Restriction time end', 'wc-alcohol'), 201 'desc' => __('Example: 09:00', 'wc-alcohol'), 202 'type' => 'text', 203 'default' => self::RESTRICTION_END 204 ); 205 206 $settings_mod[] = array( 207 'id' => self::MOD_SETTINGS_CATEGORY, 208 'name' => __('Restricted categories', 'wc-alcohol'), 209 'type' => 'multiselect', 210 'class' => 'wc-enhanced-select', 211 'options' => $this->categories_list, 212 'default' => self::RESTRICTION_CATEGORY, 213 'custom_attributes' => array( 214 'data-placeholder' => esc_html__('Select restricted categories', 'wc-alcohol'), 215 ) 216 ); 217 218 $settings_mod[] = array( 219 'id' => self::MOD_SETTINGS_WARNING, 220 'type' => 'textarea', 221 'name' => __('Warning message', 'wc-alcohol'), 222 'desc_tip' => __('Warning message displayed to the customers when trying to purchase products from the selected categories during restriction hours.', 'wc-alcohol'), 223 'desc' => __('Format: <code>%1$s</code> - Category, <code>%2$s</code> - Restriction time start, <code>%3$s</code> - Restriction time end', 'wc-alcohol'), 224 'default' => esc_html__('The sale of products in the "%1$s" category is prohibited from %2$s to %3$s.', 'wc-alcohol') 225 ); 226 227 $settings_mod[] = array( 228 'id' => self::MOD_SETTINGS_WARN_PRODUCT, 229 'type' => 'checkbox', 230 'title' => __('Show warning on', 'wc-alcohol'), 231 'desc' => __('Product pages', 'wc-alcohol'), 232 'default' => 'yes', 233 'checkboxgroup' => 'start' 234 ); 235 236 $settings_mod[] = array( 237 'id' => self::MOD_SETTINGS_WARN_CATEGORY, 238 'type' => 'checkbox', 239 'desc' => __('Category pages', 'wc-alcohol'), 240 'default' => 'yes', 241 'checkboxgroup' => 'end' 242 ); 243 244 $settings_mod[] = array( 245 'type' => 'sectionend', 246 'id' => self::MOD_SETTINGS_SECTION 247 ); 248 249 return $settings_mod; 250 } else { 251 return $settings; 252 } 253 } 254 255 protected function get_product_categories() { 256 $args = array( 257 'type' => 'product', 258 'taxonomy' => 'product_cat', 259 'hierarchical' => true, 260 'hide_empty' => 0 261 ); 262 263 //https://developer.wordpress.org/reference/functions/get_categories/ 264 $categories = get_categories($args); 265 266 if(empty($categories) || is_wp_error($categories)) 267 return array(); 268 269 return $categories; 270 } 271 #endregion 272 273 protected function validate_product($product_id, $notify = true) { 274 try { 275 if($this->validate()) 276 return true; 277 278 $restricted_category = $this->get_product_restricted_category($product_id); 279 280 if(!self::string_empty($restricted_category)) { 281 if($notify) { 282 $warning_message = $this->get_warning_message($restricted_category); 283 if(!self::string_empty($warning_message)) 284 wc_add_notice($warning_message, 'error'); 285 } 286 287 return false; 288 } 289 } catch(Exception $ex) { 290 $this->log($ex, WC_Log_Levels::ERROR); 291 } 292 293 return true; 294 } 295 296 protected function get_product_restricted_category($product_id) { 297 //https://developer.wordpress.org/reference/functions/get_the_terms/ 298 $categories = get_the_terms($product_id, 'product_cat'); 299 300 if(empty($categories) || is_wp_error($categories)) 301 return null; 302 303 foreach($categories as $category) { 304 if($this->is_restricted_category($category->slug)) 305 return $category->slug; //return first found restricted product category 306 } 307 308 return null; 309 } 310 311 protected function validate_category($category) { 312 try { 313 if($this->validate()) 314 return true; 315 316 if($this->is_restricted_category($category->slug)) 317 return false; 318 } catch(Exception $ex) { 319 $this->log($ex, WC_Log_Levels::ERROR); 320 } 321 322 return true; 323 } 324 325 protected function validate() { 326 if(!$this->enabled) 327 return true; 328 329 $current_hour = intval(current_time('Hi')); 330 if($this->restriction_start_value > $this->restriction_end_value) { 331 //overnight restriction 332 if($current_hour < $this->restriction_start_value && $current_hour >= $this->restriction_end_value) 333 return true; 334 } else { 335 //intraday restrction 336 if($current_hour < $this->restriction_start_value || $current_hour >= $this->restriction_end_value) 337 return true; 338 } 339 340 return false; 341 } 342 343 #region WooCommerce hooks 344 public function is_purchasable($is_purchasable, $object) { 345 if(!$this->validate_product($object->get_id(), false)) 346 $is_purchasable = false; 347 348 return $is_purchasable; 349 } 350 351 public function single_product_summary() { 352 if(!$this->warn_product) 353 return; 354 355 global $product; 356 $product_id = $product->get_id(); 357 358 if(!$this->validate_product($product_id, false)) { 359 $restricted_category = $this->get_product_restricted_category($product_id); 360 $warning_message = $this->get_warning_message($restricted_category); 361 echo sprintf('<p class="stock out-of-stock">%1$s</p>', $warning_message); 362 } 363 } 364 365 public function archive_description() { 366 if(!$this->warn_category) 367 return; 368 369 if(is_product_category()) { 370 global $wp_query; 371 $category = $wp_query->get_queried_object(); 372 373 if(empty($category) || is_wp_error($category)) 374 return; 375 376 if(!$this->validate_category($category)) { 377 $warning_message = $this->get_warning_message($category->slug); 378 if(!self::string_empty($warning_message)) { 379 echo sprintf('<div class="term-description">%1$s</div>', wc_format_content($warning_message)); 380 //wc_add_notice($warning_message, 'error'); 381 } 382 } 383 } 384 } 385 #endregion 386 387 protected function is_restricted_category($category_slug) { 388 return in_array($category_slug, $this->restricted_categories, true); 389 } 390 391 protected function get_warning_message($category_slug) { 392 $category_name = $this->categories_list[$category_slug]; 393 $warning_message = do_shortcode(wp_kses_post(sprintf($this->warning_template, $category_name, $this->restriction_start, $this->restriction_end))); 394 395 return $warning_message; 396 } 397 398 protected function log($message, $level = WC_Log_Levels::DEBUG) { 399 //https://woocommerce.wordpress.com/2017/01/26/improved-logging-in-woocommerce-2-7/ 400 //https://stackoverflow.com/questions/1423157/print-php-call-stack 401 $logger = wc_get_logger(); 402 $log_context = array('source' => self::MOD_ID); 403 $logger->log($level, $message, $log_context); 404 } 405 406 protected static function string_empty($string) { 407 return is_null($string) || strlen($string) === 0; 408 } 409 } 410 411 //https://docs.woocommerce.com/document/query-whether-woocommerce-is-activated/ 412 if(!class_exists('WooCommerce')) { 413 add_action('plugins_loaded', array(WC_Alcohol::class, 'get_instance')); 414 } 415 endif; 416 417 #region WooCommerce HPOS compatibility 418 //https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility 419 add_action('before_woocommerce_init', function() { 420 if(class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { 421 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); 422 } 423 }); 424 #endregion 66 // WooCommerce Product Object Caching compatibility 67 // https://developer.woocommerce.com/2026/01/19/experimental-product-object-caching-in-woocommerce-10-5/ 68 // https://github.com/woocommerce/woocommerce/pull/62041 69 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('product_instance_caching', __FILE__, true); 70 } 71 } 72 ); 73 //endregion
Note: See TracChangeset
for help on using the changeset viewer.
