close

Plugin Directory

Changeset 3458131


Ignore:
Timestamp:
02/10/2026 02:48:00 PM (3 months ago)
Author:
alexminza
Message:

Update to version 1.2.0 from GitHub

Location:
wc-alcohol
Files:
4 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wc-alcohol/tags/1.2.0/composer.json

    r3342830 r3458131  
    11{
    22    "name": "alexminza/wc-alcohol",
    3     "description": "Alcohol Sale Restrictions for WooCommerce",
     3    "description": "Products Sale Restrictions for WooCommerce",
    44    "type": "wordpress-plugin",
    5     "keywords": ["WooCommerce", "alcohol", "sale", "time", "restriction"],
     5    "keywords": [
     6        "WooCommerce",
     7        "products",
     8        "sale",
     9        "time",
     10        "restriction"
     11    ],
    612    "homepage": "https://github.com/alexminza/wc-alcohol",
    713    "license": "GPL-3.0-or-later",
     
    1925    },
    2026    "require": {
    21         "php": ">=7.0"
     27        "php": ">=7.2.5"
    2228    },
    2329    "config": {
    2430        "platform": {
    25             "php": "7.0"
     31            "php": "7.2.5"
     32        },
     33        "allow-plugins": {
     34            "dealerdirect/phpcodesniffer-composer-installer": true
    2635        }
     36    },
     37    "prefer-stable": true,
     38    "require-dev": {
     39        "woocommerce/woocommerce-sniffs": "^1.0"
    2740    }
    2841}
  • wc-alcohol/tags/1.2.0/languages/wc-alcohol-ro_RO.po

    r3342830 r3458131  
    11# Copyright (C) 2025 Alexander Minza
    2 # This file is distributed under the same license as the Alcohol Sale Restrictions for WooCommerce package.
     2# This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package.
    33msgid ""
    44msgstr ""
    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"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n"
    7 "POT-Creation-Date: 2025-08-11 14:30+0300\n"
    8 "PO-Revision-Date: 2025-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"
    99"Last-Translator: Alexander Minza <alex@alexminza.com>\n"
    1010"Language-Team: \n"
     
    1515"Plural-Forms: nplurals=3; plural=(n==1?0:(((n%100>19)||((n%100==0)&&(n!=0)))?"
    1616"2:1));\n"
    17 "X-Generator: Poedit 3.6\n"
     17"X-Generator: Poedit 3.8\n"
    1818
    1919#. Plugin Name of the plugin
    2020#: wc-alcohol.php
    21 msgid "Alcohol Sale Restrictions for WooCommerce"
    22 msgstr "Restricții vânzare alcool pentru WooCommerce"
     21msgid "Products Sale Restrictions for WooCommerce"
     22msgstr "Restricții vânzare produse pentru WooCommerce"
    2323
    2424#. Description of the plugin
    25 #: wc-alcohol.php wc-alcohol.php:179
    26 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
     26msgid "Products sale limitations during restriction hours."
     27msgstr "Limitări de vânzare produse în timpul orelor de restricție."
    2828
    29 #: wc-alcohol.php:88
    30 msgid "Alcohol sale restrictions"
    31 msgstr "Restricții vânzare alcool"
     29#: includes/class-wc-alcohol.php:76
     30msgid "Products sale restrictions"
     31msgstr "Restricții vânzare produse"
    3232
    33 #: wc-alcohol.php:158
     33#: includes/class-wc-alcohol.php:149
    3434msgid "Settings"
    3535msgstr "Setări"
    3636
    37 #: wc-alcohol.php:185
     37#: includes/class-wc-alcohol.php:178
    3838msgid "Enable restrictions"
    3939msgstr "Activează restricții"
    4040
    41 #: wc-alcohol.php:186
     41#: includes/class-wc-alcohol.php:179
    4242msgid "Enable sale limitations during restriction hours"
    43 msgstr "Activează interdicția de vânzare alcool în timpul orelor de restricție"
     43msgstr ""
     44"Activează interdicția de vânzare produse în timpul orelor de restricție"
    4445
    45 #: wc-alcohol.php:192
     46#: includes/class-wc-alcohol.php:185
    4647msgid "Restriction time start"
    4748msgstr "Început restricție"
    4849
    49 #: wc-alcohol.php:193
     50#: includes/class-wc-alcohol.php:186
    5051msgid "Example: 22:00"
    5152msgstr "Exemplu: 22:00"
    5253
    53 #: wc-alcohol.php:200
     54#: includes/class-wc-alcohol.php:196
    5455msgid "Restriction time end"
    5556msgstr "Sfârșit restricție"
    5657
    57 #: wc-alcohol.php:201
     58#: includes/class-wc-alcohol.php:197
    5859msgid "Example: 09:00"
    5960msgstr "Exemplu: 09:00"
    6061
    61 #: wc-alcohol.php:208
     62#: includes/class-wc-alcohol.php:207
    6263msgid "Restricted categories"
    6364msgstr "Categorii restricționate"
    6465
    65 #: wc-alcohol.php:214
     66#: includes/class-wc-alcohol.php:212
    6667msgid "Select restricted categories"
    6768msgstr "Selectează categoriile restricționate"
    6869
    69 #: wc-alcohol.php:221
     70#: includes/class-wc-alcohol.php:218
     71msgid "Hierarchical restriction"
     72msgstr "Restricție ierarhică"
     73
     74#: includes/class-wc-alcohol.php:219
     75msgid "Subcategories will inherit restrictions from their parent category."
     76msgstr "Subcategoriile vor moșteni restricții de la categoria părinte."
     77
     78#: includes/class-wc-alcohol.php:227
    7079msgid "Warning message"
    7180msgstr "Mesaj de avertizare"
    7281
    73 #: wc-alcohol.php:222
     82#: includes/class-wc-alcohol.php:228
    7483msgid ""
    7584"Warning message displayed to the customers when trying to purchase products "
     
    7988"din categoriile selectate în intervalul orar restricționat."
    8089
    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
    8292#, php-format
    8393msgid ""
     
    8898"restricție, <code>%3$s</code> - Sfârșit restricție"
    8999
    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
    91102#, php-format
    92103msgid ""
     
    97108"%3$s."
    98109
    99 #: wc-alcohol.php:230
     110#: includes/class-wc-alcohol.php:241
    100111msgid "Show warning on"
    101112msgstr "Arată avertisment pe"
    102113
    103 #: wc-alcohol.php:231
     114#: includes/class-wc-alcohol.php:242
    104115msgid "Product pages"
    105116msgstr "Pagini produse"
    106117
    107 #: wc-alcohol.php:239
     118#: includes/class-wc-alcohol.php:250
    108119msgid "Category pages"
    109120msgstr "Pagini categorii"
  • wc-alcohol/tags/1.2.0/languages/wc-alcohol-ru_RU.po

    r3342830 r3458131  
    11# Copyright (C) 2025 Alexander Minza
    2 # This file is distributed under the same license as the Alcohol Sale Restrictions for WooCommerce package.
     2# This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package.
    33msgid ""
    44msgstr ""
    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"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n"
    7 "POT-Creation-Date: 2025-08-11 14:30+0300\n"
    8 "PO-Revision-Date: 2025-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"
    99"Last-Translator: Alexander Minza <alex@alexminza.com>\n"
    1010"Language-Team: \n"
     
    1515"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
    1616"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"
    1818
    1919#. Plugin Name of the plugin
    2020#: wc-alcohol.php
    21 msgid "Alcohol Sale Restrictions for WooCommerce"
    22 msgstr "Ограничения продажи алкоголя для WooCommerce"
     21msgid "Products Sale Restrictions for WooCommerce"
     22msgstr "Ограничения продажи товаров для WooCommerce"
    2323
    2424#. Description of the plugin
    25 #: wc-alcohol.php wc-alcohol.php:179
    26 msgid "Alcohol sale limitations during restriction hours"
    27 msgstr "Запрет продажи алкоголя во время действия ограничений"
     25#: wc-alcohol.php includes/class-wc-alcohol.php:172
     26msgid "Products sale limitations during restriction hours."
     27msgstr "Запрет продажи товаров во время действия ограничений."
    2828
    29 #: wc-alcohol.php:88
    30 msgid "Alcohol sale restrictions"
    31 msgstr "Ограничения продажи алкоголя"
     29#: includes/class-wc-alcohol.php:76
     30msgid "Products sale restrictions"
     31msgstr "Ограничения продажи товаров"
    3232
    33 #: wc-alcohol.php:158
     33#: includes/class-wc-alcohol.php:149
    3434msgid "Settings"
    3535msgstr "Настройки"
    3636
    37 #: wc-alcohol.php:185
     37#: includes/class-wc-alcohol.php:178
    3838msgid "Enable restrictions"
    3939msgstr "Включить ограничения"
    4040
    41 #: wc-alcohol.php:186
     41#: includes/class-wc-alcohol.php:179
    4242msgid "Enable sale limitations during restriction hours"
    43 msgstr "Включить запрет продажи алкоголя во время действия ограничений"
     43msgstr "Включить запрет продажи товаров во время действия ограничений"
    4444
    45 #: wc-alcohol.php:192
     45#: includes/class-wc-alcohol.php:185
    4646msgid "Restriction time start"
    4747msgstr "Начало ограничения"
    4848
    49 #: wc-alcohol.php:193
     49#: includes/class-wc-alcohol.php:186
    5050msgid "Example: 22:00"
    5151msgstr "Пример: 22:00"
    5252
    53 #: wc-alcohol.php:200
     53#: includes/class-wc-alcohol.php:196
    5454msgid "Restriction time end"
    5555msgstr "Конец ограничения"
    5656
    57 #: wc-alcohol.php:201
     57#: includes/class-wc-alcohol.php:197
    5858msgid "Example: 09:00"
    5959msgstr "Пример: 09:00"
    6060
    61 #: wc-alcohol.php:208
     61#: includes/class-wc-alcohol.php:207
    6262msgid "Restricted categories"
    6363msgstr "Ограниченные категории"
    6464
    65 #: wc-alcohol.php:214
     65#: includes/class-wc-alcohol.php:212
    6666msgid "Select restricted categories"
    6767msgstr "Выберите ограниченные категории"
    6868
    69 #: wc-alcohol.php:221
     69#: includes/class-wc-alcohol.php:218
     70msgid "Hierarchical restriction"
     71msgstr "Иерархическое ограничение"
     72
     73#: includes/class-wc-alcohol.php:219
     74msgid "Subcategories will inherit restrictions from their parent category."
     75msgstr "Подкатегории унаследуют ограничения от родительской категории."
     76
     77#: includes/class-wc-alcohol.php:227
    7078msgid "Warning message"
    7179msgstr "Предупреждающее сообщение"
    7280
    73 #: wc-alcohol.php:222
     81#: includes/class-wc-alcohol.php:228
    7482msgid ""
    7583"Warning message displayed to the customers when trying to purchase products "
     
    7987"товары из выбранных категорий во время действия ограничений."
    8088
    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
    8291#, php-format
    8392msgid ""
     
    8897"ограничения, <code>%3$s</code> - Конец ограничения"
    8998
    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
    91101#, php-format
    92102msgid ""
     
    95105msgstr "Продажа товаров из категории “%1$s” запрещена с %2$s до %3$s."
    96106
    97 #: wc-alcohol.php:230
     107#: includes/class-wc-alcohol.php:241
    98108msgid "Show warning on"
    99109msgstr "Показывать предупреждение на"
    100110
    101 #: wc-alcohol.php:231
     111#: includes/class-wc-alcohol.php:242
    102112msgid "Product pages"
    103113msgstr "Страницах товаров"
    104114
    105 #: wc-alcohol.php:239
     115#: includes/class-wc-alcohol.php:250
    106116msgid "Category pages"
    107117msgstr "Страницах категорий"
  • wc-alcohol/tags/1.2.0/languages/wc-alcohol.pot

    r3342830 r3458131  
    1 # Copyright (C) 2025 Alexander Minza
     1# Copyright (C) 2026 Alexander Minza
    22# This file is distributed under the GPLv3 or later.
    3 #, fuzzy
    43msgid ""
    54msgstr ""
    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"
    76"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n"
    8 "POT-Creation-Date: 2025-08-11 14:30+0300\n"
     7"POT-Creation-Date: 2026-02-07 11:53+0200\n"
    98"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    109"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1312"Content-Type: text/plain; charset=UTF-8\n"
    1413"Content-Transfer-Encoding: 8bit\n"
    15 "X-Generator: Poedit 3.6\n"
     14"X-Generator: Poedit 3.8\n"
    1615
    1716#. Plugin Name of the plugin
    1817#: wc-alcohol.php
    19 msgid "Alcohol Sale Restrictions for WooCommerce"
     18msgid "Products Sale Restrictions for WooCommerce"
    2019msgstr ""
    2120
    2221#. Description of the plugin
    23 #: wc-alcohol.php wc-alcohol.php:179
    24 msgid "Alcohol sale limitations during restriction hours"
     22#: wc-alcohol.php includes/class-wc-alcohol.php:172
     23msgid "Products sale limitations during restriction hours."
    2524msgstr ""
    2625
    27 #: wc-alcohol.php:88
    28 msgid "Alcohol sale restrictions"
     26#: includes/class-wc-alcohol.php:76
     27msgid "Products sale restrictions"
    2928msgstr ""
    3029
    31 #: wc-alcohol.php:158
     30#: includes/class-wc-alcohol.php:149
    3231msgid "Settings"
    3332msgstr ""
    3433
    35 #: wc-alcohol.php:185
     34#: includes/class-wc-alcohol.php:178
    3635msgid "Enable restrictions"
    3736msgstr ""
    3837
    39 #: wc-alcohol.php:186
     38#: includes/class-wc-alcohol.php:179
    4039msgid "Enable sale limitations during restriction hours"
    4140msgstr ""
    4241
    43 #: wc-alcohol.php:192
     42#: includes/class-wc-alcohol.php:185
    4443msgid "Restriction time start"
    4544msgstr ""
    4645
    47 #: wc-alcohol.php:193
     46#: includes/class-wc-alcohol.php:186
    4847msgid "Example: 22:00"
    4948msgstr ""
    5049
    51 #: wc-alcohol.php:200
     50#: includes/class-wc-alcohol.php:196
    5251msgid "Restriction time end"
    5352msgstr ""
    5453
    55 #: wc-alcohol.php:201
     54#: includes/class-wc-alcohol.php:197
    5655msgid "Example: 09:00"
    5756msgstr ""
    5857
    59 #: wc-alcohol.php:208
     58#: includes/class-wc-alcohol.php:207
    6059msgid "Restricted categories"
    6160msgstr ""
    6261
    63 #: wc-alcohol.php:214
     62#: includes/class-wc-alcohol.php:212
    6463msgid "Select restricted categories"
    6564msgstr ""
    6665
    67 #: wc-alcohol.php:221
     66#: includes/class-wc-alcohol.php:218
     67msgid "Hierarchical restriction"
     68msgstr ""
     69
     70#: includes/class-wc-alcohol.php:219
     71msgid "Subcategories will inherit restrictions from their parent category."
     72msgstr ""
     73
     74#: includes/class-wc-alcohol.php:227
    6875msgid "Warning message"
    6976msgstr ""
    7077
    71 #: wc-alcohol.php:222
     78#: includes/class-wc-alcohol.php:228
    7279msgid "Warning message displayed to the customers when trying to purchase products from the selected categories during restriction hours."
    7380msgstr ""
    7481
    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
    7684#, php-format
    7785msgid "Format: <code>%1$s</code> - Category, <code>%2$s</code> - Restriction time start, <code>%3$s</code> - Restriction time end"
    7886msgstr ""
    7987
    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
    8190#, php-format
    8291msgid "The sale of products in the \"%1$s\" category is prohibited from %2$s to %3$s."
    8392msgstr ""
    8493
    85 #: wc-alcohol.php:230
     94#: includes/class-wc-alcohol.php:241
    8695msgid "Show warning on"
    8796msgstr ""
    8897
    89 #: wc-alcohol.php:231
     98#: includes/class-wc-alcohol.php:242
    9099msgid "Product pages"
    91100msgstr ""
    92101
    93 #: wc-alcohol.php:239
     102#: includes/class-wc-alcohol.php:250
    94103msgid "Category pages"
    95104msgstr ""
  • wc-alcohol/tags/1.2.0/readme.txt

    r3342830 r3458131  
    1 === Alcohol Sale Restrictions for WooCommerce ===
     1=== Products Sale Restrictions for WooCommerce ===
    22Contributors: alexminza
    3 Donate link: https://www.revolut.me/alexminza
    4 Tags: WooCommerce, alcohol, sale, time, restriction
     3Tags: WooCommerce, products, sale, time, restriction
    54Requires at least: 4.8
    6 Tested up to: 6.8
    7 Stable tag: 1.1.3
    8 Requires PHP: 7.0
     5Tested up to: 6.9
     6Stable tag: 1.2.0
     7Requires PHP: 7.2.5
    98License: GPLv3 or later
    109License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1110
     11Products sale limitations during restriction hours.
     12
    1213== Description ==
    1314
    14 Alcohol sale limitations during legal restriction hours
     15Products sale limitations during restriction hours.
    1516
    1617= Features =
     
    2627= How can I configure the plugin settings? =
    2728
    28 Use the *WooCommerce > Settings > Products > Alcohol sale restrictions* screen to configure the plugin.
     29Use the *WooCommerce > Settings > Products > Products sale restrictions* screen to configure the plugin.
    2930
    3031= How can I contribute to the plugin? =
     
    4344
    4445See [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
    4550
    4651= 1.1.3 =
     
    8590== Upgrade Notice ==
    8691
     92= 1.2.0 =
     93Code reorganization and refactoring for better maintainability.
     94
    8795= 1.1.3 =
    8896Adjusted 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  
    11<?php
     2
    23/**
    3  * Plugin Name: Alcohol Sale Restrictions for WooCommerce
    4  * Description: Alcohol sale limitations during restriction hours
     4 * Plugin Name: Products Sale Restrictions for WooCommerce
     5 * Description: Products sale limitations during restriction hours.
    56 * Plugin URI: https://wordpress.org/plugins/wc-alcohol/
    6  * Version: 1.1.3
     7 * Version: 1.2.0
    78 * Author: Alexander Minza
    89 * Author URI: https://profiles.wordpress.org/alexminza
     
    1314 * License: GPLv3 or later
    1415 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
    15  * Requires PHP: 7.0
     16 * Requires PHP: 7.2.5
    1617 * Requires at least: 4.8
    17  * Tested up to: 6.8
    18  * WC requires at least: 3.2
    19  * WC tested up to: 10.0.4
     18 * Tested up to: 6.9
     19 * WC requires at least: 3.3
     20 * WC tested up to: 10.5.0
    2021 * Requires Plugins: woocommerce
     22 *
     23 * @package wc-alcohol
    2124 */
    2225
    23 //Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol
     26// Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol
    2427
    25 if(!defined('ABSPATH')) {
    26     exit; // Exit if accessed directly
     28declare(strict_types=1);
     29
     30namespace AlexMinza\WC_Alcohol;
     31
     32if (!defined('ABSPATH')) {
     33    exit; // Exit if accessed directly
    2734}
    2835
    29 if(!class_exists(WC_Alcohol::class)):
    30     class WC_Alcohol {
    31         #region Constants
    32         const MOD_ID          = 'wc-alcohol';
     36add_action('plugins_loaded', __NAMESPACE__ . '\alcohol_plugins_loaded_init');
    3337
    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';
     38function alcohol_plugins_loaded_init()
     39{
     40    if (!class_exists('WC_Settings_API')) {
     41        return;
     42    }
    4343
    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';
    4845
    49         /**
    50          * Instance of this class.
    51          *
    52          * @var object
    53          */
    54         protected static $instance = null;
     46    WC_Alcohol::get_instance();
    5547
    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}
    5852
    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
     54add_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);
    6761
    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);
    7065
    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  
    11{
    22    "name": "alexminza/wc-alcohol",
    3     "description": "Alcohol Sale Restrictions for WooCommerce",
     3    "description": "Products Sale Restrictions for WooCommerce",
    44    "type": "wordpress-plugin",
    5     "keywords": ["WooCommerce", "alcohol", "sale", "time", "restriction"],
     5    "keywords": [
     6        "WooCommerce",
     7        "products",
     8        "sale",
     9        "time",
     10        "restriction"
     11    ],
    612    "homepage": "https://github.com/alexminza/wc-alcohol",
    713    "license": "GPL-3.0-or-later",
     
    1925    },
    2026    "require": {
    21         "php": ">=7.0"
     27        "php": ">=7.2.5"
    2228    },
    2329    "config": {
    2430        "platform": {
    25             "php": "7.0"
     31            "php": "7.2.5"
     32        },
     33        "allow-plugins": {
     34            "dealerdirect/phpcodesniffer-composer-installer": true
    2635        }
     36    },
     37    "prefer-stable": true,
     38    "require-dev": {
     39        "woocommerce/woocommerce-sniffs": "^1.0"
    2740    }
    2841}
  • wc-alcohol/trunk/languages/wc-alcohol-ro_RO.po

    r3342830 r3458131  
    11# Copyright (C) 2025 Alexander Minza
    2 # This file is distributed under the same license as the Alcohol Sale Restrictions for WooCommerce package.
     2# This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package.
    33msgid ""
    44msgstr ""
    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"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n"
    7 "POT-Creation-Date: 2025-08-11 14:30+0300\n"
    8 "PO-Revision-Date: 2025-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"
    99"Last-Translator: Alexander Minza <alex@alexminza.com>\n"
    1010"Language-Team: \n"
     
    1515"Plural-Forms: nplurals=3; plural=(n==1?0:(((n%100>19)||((n%100==0)&&(n!=0)))?"
    1616"2:1));\n"
    17 "X-Generator: Poedit 3.6\n"
     17"X-Generator: Poedit 3.8\n"
    1818
    1919#. Plugin Name of the plugin
    2020#: wc-alcohol.php
    21 msgid "Alcohol Sale Restrictions for WooCommerce"
    22 msgstr "Restricții vânzare alcool pentru WooCommerce"
     21msgid "Products Sale Restrictions for WooCommerce"
     22msgstr "Restricții vânzare produse pentru WooCommerce"
    2323
    2424#. Description of the plugin
    25 #: wc-alcohol.php wc-alcohol.php:179
    26 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
     26msgid "Products sale limitations during restriction hours."
     27msgstr "Limitări de vânzare produse în timpul orelor de restricție."
    2828
    29 #: wc-alcohol.php:88
    30 msgid "Alcohol sale restrictions"
    31 msgstr "Restricții vânzare alcool"
     29#: includes/class-wc-alcohol.php:76
     30msgid "Products sale restrictions"
     31msgstr "Restricții vânzare produse"
    3232
    33 #: wc-alcohol.php:158
     33#: includes/class-wc-alcohol.php:149
    3434msgid "Settings"
    3535msgstr "Setări"
    3636
    37 #: wc-alcohol.php:185
     37#: includes/class-wc-alcohol.php:178
    3838msgid "Enable restrictions"
    3939msgstr "Activează restricții"
    4040
    41 #: wc-alcohol.php:186
     41#: includes/class-wc-alcohol.php:179
    4242msgid "Enable sale limitations during restriction hours"
    43 msgstr "Activează interdicția de vânzare alcool în timpul orelor de restricție"
     43msgstr ""
     44"Activează interdicția de vânzare produse în timpul orelor de restricție"
    4445
    45 #: wc-alcohol.php:192
     46#: includes/class-wc-alcohol.php:185
    4647msgid "Restriction time start"
    4748msgstr "Început restricție"
    4849
    49 #: wc-alcohol.php:193
     50#: includes/class-wc-alcohol.php:186
    5051msgid "Example: 22:00"
    5152msgstr "Exemplu: 22:00"
    5253
    53 #: wc-alcohol.php:200
     54#: includes/class-wc-alcohol.php:196
    5455msgid "Restriction time end"
    5556msgstr "Sfârșit restricție"
    5657
    57 #: wc-alcohol.php:201
     58#: includes/class-wc-alcohol.php:197
    5859msgid "Example: 09:00"
    5960msgstr "Exemplu: 09:00"
    6061
    61 #: wc-alcohol.php:208
     62#: includes/class-wc-alcohol.php:207
    6263msgid "Restricted categories"
    6364msgstr "Categorii restricționate"
    6465
    65 #: wc-alcohol.php:214
     66#: includes/class-wc-alcohol.php:212
    6667msgid "Select restricted categories"
    6768msgstr "Selectează categoriile restricționate"
    6869
    69 #: wc-alcohol.php:221
     70#: includes/class-wc-alcohol.php:218
     71msgid "Hierarchical restriction"
     72msgstr "Restricție ierarhică"
     73
     74#: includes/class-wc-alcohol.php:219
     75msgid "Subcategories will inherit restrictions from their parent category."
     76msgstr "Subcategoriile vor moșteni restricții de la categoria părinte."
     77
     78#: includes/class-wc-alcohol.php:227
    7079msgid "Warning message"
    7180msgstr "Mesaj de avertizare"
    7281
    73 #: wc-alcohol.php:222
     82#: includes/class-wc-alcohol.php:228
    7483msgid ""
    7584"Warning message displayed to the customers when trying to purchase products "
     
    7988"din categoriile selectate în intervalul orar restricționat."
    8089
    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
    8292#, php-format
    8393msgid ""
     
    8898"restricție, <code>%3$s</code> - Sfârșit restricție"
    8999
    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
    91102#, php-format
    92103msgid ""
     
    97108"%3$s."
    98109
    99 #: wc-alcohol.php:230
     110#: includes/class-wc-alcohol.php:241
    100111msgid "Show warning on"
    101112msgstr "Arată avertisment pe"
    102113
    103 #: wc-alcohol.php:231
     114#: includes/class-wc-alcohol.php:242
    104115msgid "Product pages"
    105116msgstr "Pagini produse"
    106117
    107 #: wc-alcohol.php:239
     118#: includes/class-wc-alcohol.php:250
    108119msgid "Category pages"
    109120msgstr "Pagini categorii"
  • wc-alcohol/trunk/languages/wc-alcohol-ru_RU.po

    r3342830 r3458131  
    11# Copyright (C) 2025 Alexander Minza
    2 # This file is distributed under the same license as the Alcohol Sale Restrictions for WooCommerce package.
     2# This file is distributed under the same license as the Products Sale Restrictions for WooCommerce package.
    33msgid ""
    44msgstr ""
    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"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n"
    7 "POT-Creation-Date: 2025-08-11 14:30+0300\n"
    8 "PO-Revision-Date: 2025-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"
    99"Last-Translator: Alexander Minza <alex@alexminza.com>\n"
    1010"Language-Team: \n"
     
    1515"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
    1616"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"
    1818
    1919#. Plugin Name of the plugin
    2020#: wc-alcohol.php
    21 msgid "Alcohol Sale Restrictions for WooCommerce"
    22 msgstr "Ограничения продажи алкоголя для WooCommerce"
     21msgid "Products Sale Restrictions for WooCommerce"
     22msgstr "Ограничения продажи товаров для WooCommerce"
    2323
    2424#. Description of the plugin
    25 #: wc-alcohol.php wc-alcohol.php:179
    26 msgid "Alcohol sale limitations during restriction hours"
    27 msgstr "Запрет продажи алкоголя во время действия ограничений"
     25#: wc-alcohol.php includes/class-wc-alcohol.php:172
     26msgid "Products sale limitations during restriction hours."
     27msgstr "Запрет продажи товаров во время действия ограничений."
    2828
    29 #: wc-alcohol.php:88
    30 msgid "Alcohol sale restrictions"
    31 msgstr "Ограничения продажи алкоголя"
     29#: includes/class-wc-alcohol.php:76
     30msgid "Products sale restrictions"
     31msgstr "Ограничения продажи товаров"
    3232
    33 #: wc-alcohol.php:158
     33#: includes/class-wc-alcohol.php:149
    3434msgid "Settings"
    3535msgstr "Настройки"
    3636
    37 #: wc-alcohol.php:185
     37#: includes/class-wc-alcohol.php:178
    3838msgid "Enable restrictions"
    3939msgstr "Включить ограничения"
    4040
    41 #: wc-alcohol.php:186
     41#: includes/class-wc-alcohol.php:179
    4242msgid "Enable sale limitations during restriction hours"
    43 msgstr "Включить запрет продажи алкоголя во время действия ограничений"
     43msgstr "Включить запрет продажи товаров во время действия ограничений"
    4444
    45 #: wc-alcohol.php:192
     45#: includes/class-wc-alcohol.php:185
    4646msgid "Restriction time start"
    4747msgstr "Начало ограничения"
    4848
    49 #: wc-alcohol.php:193
     49#: includes/class-wc-alcohol.php:186
    5050msgid "Example: 22:00"
    5151msgstr "Пример: 22:00"
    5252
    53 #: wc-alcohol.php:200
     53#: includes/class-wc-alcohol.php:196
    5454msgid "Restriction time end"
    5555msgstr "Конец ограничения"
    5656
    57 #: wc-alcohol.php:201
     57#: includes/class-wc-alcohol.php:197
    5858msgid "Example: 09:00"
    5959msgstr "Пример: 09:00"
    6060
    61 #: wc-alcohol.php:208
     61#: includes/class-wc-alcohol.php:207
    6262msgid "Restricted categories"
    6363msgstr "Ограниченные категории"
    6464
    65 #: wc-alcohol.php:214
     65#: includes/class-wc-alcohol.php:212
    6666msgid "Select restricted categories"
    6767msgstr "Выберите ограниченные категории"
    6868
    69 #: wc-alcohol.php:221
     69#: includes/class-wc-alcohol.php:218
     70msgid "Hierarchical restriction"
     71msgstr "Иерархическое ограничение"
     72
     73#: includes/class-wc-alcohol.php:219
     74msgid "Subcategories will inherit restrictions from their parent category."
     75msgstr "Подкатегории унаследуют ограничения от родительской категории."
     76
     77#: includes/class-wc-alcohol.php:227
    7078msgid "Warning message"
    7179msgstr "Предупреждающее сообщение"
    7280
    73 #: wc-alcohol.php:222
     81#: includes/class-wc-alcohol.php:228
    7482msgid ""
    7583"Warning message displayed to the customers when trying to purchase products "
     
    7987"товары из выбранных категорий во время действия ограничений."
    8088
    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
    8291#, php-format
    8392msgid ""
     
    8897"ограничения, <code>%3$s</code> - Конец ограничения"
    8998
    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
    91101#, php-format
    92102msgid ""
     
    95105msgstr "Продажа товаров из категории “%1$s” запрещена с %2$s до %3$s."
    96106
    97 #: wc-alcohol.php:230
     107#: includes/class-wc-alcohol.php:241
    98108msgid "Show warning on"
    99109msgstr "Показывать предупреждение на"
    100110
    101 #: wc-alcohol.php:231
     111#: includes/class-wc-alcohol.php:242
    102112msgid "Product pages"
    103113msgstr "Страницах товаров"
    104114
    105 #: wc-alcohol.php:239
     115#: includes/class-wc-alcohol.php:250
    106116msgid "Category pages"
    107117msgstr "Страницах категорий"
  • wc-alcohol/trunk/languages/wc-alcohol.pot

    r3342830 r3458131  
    1 # Copyright (C) 2025 Alexander Minza
     1# Copyright (C) 2026 Alexander Minza
    22# This file is distributed under the GPLv3 or later.
    3 #, fuzzy
    43msgid ""
    54msgstr ""
    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"
    76"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wc-alcohol\n"
    8 "POT-Creation-Date: 2025-08-11 14:30+0300\n"
     7"POT-Creation-Date: 2026-02-07 11:53+0200\n"
    98"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    109"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1312"Content-Type: text/plain; charset=UTF-8\n"
    1413"Content-Transfer-Encoding: 8bit\n"
    15 "X-Generator: Poedit 3.6\n"
     14"X-Generator: Poedit 3.8\n"
    1615
    1716#. Plugin Name of the plugin
    1817#: wc-alcohol.php
    19 msgid "Alcohol Sale Restrictions for WooCommerce"
     18msgid "Products Sale Restrictions for WooCommerce"
    2019msgstr ""
    2120
    2221#. Description of the plugin
    23 #: wc-alcohol.php wc-alcohol.php:179
    24 msgid "Alcohol sale limitations during restriction hours"
     22#: wc-alcohol.php includes/class-wc-alcohol.php:172
     23msgid "Products sale limitations during restriction hours."
    2524msgstr ""
    2625
    27 #: wc-alcohol.php:88
    28 msgid "Alcohol sale restrictions"
     26#: includes/class-wc-alcohol.php:76
     27msgid "Products sale restrictions"
    2928msgstr ""
    3029
    31 #: wc-alcohol.php:158
     30#: includes/class-wc-alcohol.php:149
    3231msgid "Settings"
    3332msgstr ""
    3433
    35 #: wc-alcohol.php:185
     34#: includes/class-wc-alcohol.php:178
    3635msgid "Enable restrictions"
    3736msgstr ""
    3837
    39 #: wc-alcohol.php:186
     38#: includes/class-wc-alcohol.php:179
    4039msgid "Enable sale limitations during restriction hours"
    4140msgstr ""
    4241
    43 #: wc-alcohol.php:192
     42#: includes/class-wc-alcohol.php:185
    4443msgid "Restriction time start"
    4544msgstr ""
    4645
    47 #: wc-alcohol.php:193
     46#: includes/class-wc-alcohol.php:186
    4847msgid "Example: 22:00"
    4948msgstr ""
    5049
    51 #: wc-alcohol.php:200
     50#: includes/class-wc-alcohol.php:196
    5251msgid "Restriction time end"
    5352msgstr ""
    5453
    55 #: wc-alcohol.php:201
     54#: includes/class-wc-alcohol.php:197
    5655msgid "Example: 09:00"
    5756msgstr ""
    5857
    59 #: wc-alcohol.php:208
     58#: includes/class-wc-alcohol.php:207
    6059msgid "Restricted categories"
    6160msgstr ""
    6261
    63 #: wc-alcohol.php:214
     62#: includes/class-wc-alcohol.php:212
    6463msgid "Select restricted categories"
    6564msgstr ""
    6665
    67 #: wc-alcohol.php:221
     66#: includes/class-wc-alcohol.php:218
     67msgid "Hierarchical restriction"
     68msgstr ""
     69
     70#: includes/class-wc-alcohol.php:219
     71msgid "Subcategories will inherit restrictions from their parent category."
     72msgstr ""
     73
     74#: includes/class-wc-alcohol.php:227
    6875msgid "Warning message"
    6976msgstr ""
    7077
    71 #: wc-alcohol.php:222
     78#: includes/class-wc-alcohol.php:228
    7279msgid "Warning message displayed to the customers when trying to purchase products from the selected categories during restriction hours."
    7380msgstr ""
    7481
    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
    7684#, php-format
    7785msgid "Format: <code>%1$s</code> - Category, <code>%2$s</code> - Restriction time start, <code>%3$s</code> - Restriction time end"
    7886msgstr ""
    7987
    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
    8190#, php-format
    8291msgid "The sale of products in the \"%1$s\" category is prohibited from %2$s to %3$s."
    8392msgstr ""
    8493
    85 #: wc-alcohol.php:230
     94#: includes/class-wc-alcohol.php:241
    8695msgid "Show warning on"
    8796msgstr ""
    8897
    89 #: wc-alcohol.php:231
     98#: includes/class-wc-alcohol.php:242
    9099msgid "Product pages"
    91100msgstr ""
    92101
    93 #: wc-alcohol.php:239
     102#: includes/class-wc-alcohol.php:250
    94103msgid "Category pages"
    95104msgstr ""
  • wc-alcohol/trunk/readme.txt

    r3342830 r3458131  
    1 === Alcohol Sale Restrictions for WooCommerce ===
     1=== Products Sale Restrictions for WooCommerce ===
    22Contributors: alexminza
    3 Donate link: https://www.revolut.me/alexminza
    4 Tags: WooCommerce, alcohol, sale, time, restriction
     3Tags: WooCommerce, products, sale, time, restriction
    54Requires at least: 4.8
    6 Tested up to: 6.8
    7 Stable tag: 1.1.3
    8 Requires PHP: 7.0
     5Tested up to: 6.9
     6Stable tag: 1.2.0
     7Requires PHP: 7.2.5
    98License: GPLv3 or later
    109License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1110
     11Products sale limitations during restriction hours.
     12
    1213== Description ==
    1314
    14 Alcohol sale limitations during legal restriction hours
     15Products sale limitations during restriction hours.
    1516
    1617= Features =
     
    2627= How can I configure the plugin settings? =
    2728
    28 Use the *WooCommerce > Settings > Products > Alcohol sale restrictions* screen to configure the plugin.
     29Use the *WooCommerce > Settings > Products > Products sale restrictions* screen to configure the plugin.
    2930
    3031= How can I contribute to the plugin? =
     
    4344
    4445See [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
    4550
    4651= 1.1.3 =
     
    8590== Upgrade Notice ==
    8691
     92= 1.2.0 =
     93Code reorganization and refactoring for better maintainability.
     94
    8795= 1.1.3 =
    8896Adjusted plugin name to comply with the [WooCommerce trademark guidelines](https://woocommerce.com/trademark-guidelines/).
  • wc-alcohol/trunk/wc-alcohol.php

    r3342830 r3458131  
    11<?php
     2
    23/**
    3  * Plugin Name: Alcohol Sale Restrictions for WooCommerce
    4  * Description: Alcohol sale limitations during restriction hours
     4 * Plugin Name: Products Sale Restrictions for WooCommerce
     5 * Description: Products sale limitations during restriction hours.
    56 * Plugin URI: https://wordpress.org/plugins/wc-alcohol/
    6  * Version: 1.1.3
     7 * Version: 1.2.0
    78 * Author: Alexander Minza
    89 * Author URI: https://profiles.wordpress.org/alexminza
     
    1314 * License: GPLv3 or later
    1415 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
    15  * Requires PHP: 7.0
     16 * Requires PHP: 7.2.5
    1617 * Requires at least: 4.8
    17  * Tested up to: 6.8
    18  * WC requires at least: 3.2
    19  * WC tested up to: 10.0.4
     18 * Tested up to: 6.9
     19 * WC requires at least: 3.3
     20 * WC tested up to: 10.5.0
    2021 * Requires Plugins: woocommerce
     22 *
     23 * @package wc-alcohol
    2124 */
    2225
    23 //Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol
     26// Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol
    2427
    25 if(!defined('ABSPATH')) {
    26     exit; // Exit if accessed directly
     28declare(strict_types=1);
     29
     30namespace AlexMinza\WC_Alcohol;
     31
     32if (!defined('ABSPATH')) {
     33    exit; // Exit if accessed directly
    2734}
    2835
    29 if(!class_exists(WC_Alcohol::class)):
    30     class WC_Alcohol {
    31         #region Constants
    32         const MOD_ID          = 'wc-alcohol';
     36add_action('plugins_loaded', __NAMESPACE__ . '\alcohol_plugins_loaded_init');
    3337
    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';
     38function alcohol_plugins_loaded_init()
     39{
     40    if (!class_exists('WC_Settings_API')) {
     41        return;
     42    }
    4343
    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';
    4845
    49         /**
    50          * Instance of this class.
    51          *
    52          * @var object
    53          */
    54         protected static $instance = null;
     46    WC_Alcohol::get_instance();
    5547
    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}
    5852
    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
     54add_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);
    6761
    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);
    7065
    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.