Plugin Directory

Changeset 3492415


Ignore:
Timestamp:
03/27/2026 07:48:29 AM (30 hours ago)
Author:
addonsorg
Message:

Release new version

Location:
yeediscounts
Files:
45 added
6 edited

Legend:

Unmodified
Added
Removed
  • yeediscounts/trunk/assets/admin-rules.js

    r3454353 r3492415  
    458458            const $bxgyBlock = $('.yeekit-buyx-gety-block');
    459459            const $titleRow = $('.yeekit-discount-title-row');
     460            const $rulesBlock = $('#yeekit-dd-conditions-wrap').closest('.yeekit-dd-block');
     461            const $discountBarBlock = $('.yeekit-discount-bar-block');
    460462
    461463            // Reset Blocks
    462464            $filterBlock.show();
     465            $rulesBlock.show();
     466            $discountBarBlock.show();
    463467
    464468            $discountBlock.hide();
     
    475479            }
    476480
    477             if (type === 'yeekit_simple_discount' || type === 'yeekit_cart_discount' || type === 'not_selected' || !type) {
     481            // If no type is selected, hide everything else
     482            if (!type || type === 'not_selected') {
     483                $filterBlock.hide();
     484                $rulesBlock.hide();
     485                $discountBarBlock.hide();
     486                $discountBlock.hide();
     487                return;
     488            }
     489
     490            if (type === 'yeekit_simple_discount' || type === 'yeekit_cart_discount') {
    478491                $discountBlock.show();
    479492                // Show title ONLY for cart discount
  • yeediscounts/trunk/backend/blocks/general.php

    r3454353 r3492415  
    5959                        <select name="rule[type]"
    6060                            class="yeekit-product-discount-type yeekit-discount-type-selector">
    61                             <option value="not_selected"><?php esc_html_e('Select Discount Type', 'yeediscounts'); ?></option>
     61                            <option value=""><?php esc_html_e('Select Discount Type', 'yeediscounts'); ?></option>
    6262                            <optgroup label="<?php esc_attr_e('Simple Discount', 'yeediscounts'); ?>">
    6363                                <option value="yeekit_simple_discount" <?php selected($rule['type'] ?? '', 'yeekit_simple_discount'); ?>><?php esc_html_e('Product Adjustment', 'yeediscounts'); ?></option>
  • yeediscounts/trunk/frontend/bulk_table.php

    r3454353 r3492415  
    3333        $rules = Yeekit_Dynamic_Discounts_Rules_Manager::get_active_rules();
    3434        foreach ($rules as $rule) {
    35             if (empty($rule['type']) || $rule['type'] !== 'yeekit_buy_x_get_x') {
     35            $type = $rule['type'] ?? '';
     36            $supported_types = [
     37                'yeekit_buy_x_get_x',
     38                'yeekit_buy_x_get_y',
     39                'yeekit_bulk_discount',
     40                'yeekit_set_discount'
     41            ];
     42            if (! in_array($type, $supported_types, true)) {
    3643                continue;
    3744            }
     
    4350                'quantity' => 1
    4451            ];
     52
    4553            if (Yeekit_Dynamic_Discounts_Filter::validate_item($cart_item, $rule)) {
    4654                $matched_rule = $rule;
     
    5260        }
    5361        $tiers = [];
    54         $is_bogo = ($matched_rule['type'] === 'yeekit_buy_x_get_x');
    55         if ($is_bogo) {
    56             $ranges = $matched_rule['buyx_getx_adjustments']['ranges'] ?? [];;
     62        $rule_type = $matched_rule['type'] ?? '';
     63        $is_bogo = ($rule_type === 'yeekit_buy_x_get_x');
     64        $is_bxgy = ($rule_type === 'yeekit_buy_x_get_y');
     65        $is_set = ($rule_type === 'yeekit_set_discount');
     66
     67        if ($is_bogo || $is_bxgy || $is_set) {
     68            if ($is_bogo) {
     69                $ranges = $matched_rule['buyx_getx_adjustments']['ranges'] ?? [];
     70            } elseif ($is_bxgy) {
     71                $ranges = $matched_rule['buyx_gety_adjustments']['ranges'] ?? [];
     72            } else {
     73                $ranges = $matched_rule['set_adjustments']['ranges'] ?? [];
     74            }
    5775            // Handle Recursive: Generate purely synthetic rows for display if recursive
    58             // Assuming first valid range dictates the rule for simplicity?
    59             // Or merge all? BOGO usually processes sequential ranges.
    60             // If recursive is set on a range, we expand it.
    6176            foreach ($ranges as $r) {
    6277                if (!empty($r['is_recursive'])) {
    6378                    // Generate 5 steps
    64                     $step_min = intval($r['min_qty']);
    65                     $step_get = intval($r['free_qty']);
     79                    $step_min = intval($r['min_qty'] ?? ($r['qty'] ?? 1));
     80                    $step_get = intval($r['free_qty'] ?? ($r['get_qty'] ?? 1));
    6681                    if ($step_min <= 0) $step_min = 1;
    6782                    for ($i = 1; $i <= 5; $i++) {
     
    7186                            'min_qty' => $qty_buy,
    7287                            'max_qty' => '', // Point value
    73                             'type' => $r['free_type'] ?? 'free_product',
    74                             'value' => $r['amount'] ?? 0,
     88                            'type' => $r['free_type'] ?? ($r['discount_type'] ?? ($r['type'] ?? 'percentage')),
     89                            'value' => $r['amount'] ?? ($r['discount_value'] ?? ($r['value'] ?? 0)),
    7590                            'get_qty' => $qty_get,
    7691                            'label' => __('Tier', 'yeediscounts') . ' ' . $i,
    77                             'is_generated' => true
     92                            'is_generated' => true,
     93                            'get_product' => $r['get_product'] ?? []
    7894                        ];
    7995                    }
    80                     // Recursive implies we stop processing other ranges usually?
    81                     // Let's break to avoid table flooding if multiple recursive ranges exist (rare)
    8296                    break;
    8397                } else {
    8498                    // Normal Range
    8599                    $tiers[] = [
    86                         'min_qty' => $r['min_qty'],
    87                         'max_qty' => $r['max_qty'],
    88                         'type' => $r['free_type'] ?? 'free_product',
    89                         'value' => $r['amount'] ?? 0,
    90                         'get_qty' => $r['free_qty'] ?? 0,
    91                         'label' => ''
     100                        'min_qty' => $r['min_qty'] ?? ($r['qty'] ?? 1),
     101                        'max_qty' => $r['max_qty'] ?? '',
     102                        'type' => $r['free_type'] ?? ($r['discount_type'] ?? ($r['type'] ?? 'percentage')),
     103                        'value' => $r['amount'] ?? ($r['discount_value'] ?? ($r['value'] ?? 0)),
     104                        'get_qty' => $r['free_qty'] ?? ($r['get_qty'] ?? 0),
     105                        'label' => $r['label'] ?? '',
     106                        'get_product' => $r['get_product'] ?? []
    92107                    ];
    93108                }
     
    104119        });
    105120        $product_price = floatval($product->get_price());
     121
     122        // Determine table title and headers
     123        $table_title = $matched_rule['title'] ?? '';
     124        if (empty($table_title)) {
     125            if ($is_bogo) $table_title = __('Buy X Get X', 'yeediscounts');
     126            elseif ($is_bxgy) $table_title = __('Buy X Get Y', 'yeediscounts');
     127            elseif ($is_set) $table_title = __('Bundle Discount', 'yeediscounts');
     128            else $table_title = __('Bulk Discount', 'yeediscounts');
     129        }
     130
     131        $range_header = __('Range', 'yeediscounts');
     132        if ($is_bogo || $is_bxgy) $range_header = __('Buy Quantity', 'yeediscounts');
     133        elseif ($is_set) $range_header = __('Set Quantity', 'yeediscounts');
     134
     135        $benefit_header = __('Discount', 'yeediscounts');
     136        if ($is_bogo || $is_bxgy) $benefit_header = __('Get Benefit', 'yeediscounts');
    106137?>
    107138        <div class="yeekit-bulk-table-wrapper">
    108             <h3><?php echo esc_html($is_bogo) ? esc_html__('Buy X Get X', 'yeediscounts') : esc_html__('Bulk Discount', 'yeediscounts'); ?></h3>
     139            <h3><?php echo esc_html($table_title); ?></h3>
    109140            <table id="yeekit-bulk-table" class="yeekit-bulk-table-msg yeekit-table">
    110141                <thead class="yeekit-bulk-table-thead">
     
    114145                        </th>
    115146                        <th id="yeekit-bulk-table-range" class="yeekit-bulk-table-td">
    116                             <span><?php echo esc_html($is_bogo) ? esc_html__('Buy Quantity', 'yeediscounts') : esc_html__('Range', 'yeediscounts'); ?></span>
     147                            <span><?php echo esc_html($range_header); ?></span>
    117148                        </th>
    118149                        <th id="yeekit-bulk-table-discount" class="yeekit-bulk-table-td">
    119                             <span><?php echo esc_html($is_bogo) ? esc_html__('Get Benefit', 'yeediscounts') : esc_html__('Discount', 'yeediscounts'); ?></span>
     150                            <span><?php echo esc_html($benefit_header); ?></span>
    120151                        </th>
    121152                    </tr>
     
    126157                        $max = $tier['max_qty'];
    127158                        // Range display
    128                         if ($is_bogo && !empty($tier['is_generated'])) {
     159                        if (($is_bogo || $is_bxgy || $is_set) && !empty($tier['is_generated'])) {
    129160                            $range = $min; // Point value for recursive steps
    130161                        } else {
     
    142173                        $discount_display_text = '';
    143174                        $discounted_price_text = '';
    144                         if ($is_bogo) {
    145                             // BOGO Info
     175                        $reward_desc = '';
     176
     177                        if ($is_bogo || $is_bxgy) {
     178                            // BOGO / BXGY Info
    146179                            if ($type === 'free_product') {
    147180                                /* translators: %s: Quantity */
     
    150183                                /* translators: 1: Quantity, 2: Percentage value */
    151184                                $discount_display_text = sprintf(__('Get %1$s at %2$s%% Off', 'yeediscounts'), $get_qty, $value);
    152                             } elseif ($type === 'fixed_price') {
     185                            } elseif ($type === 'fixed_price' || $type === 'fixed_set_price') {
    153186                                /* translators: 1: Quantity, 2: Price amount */
    154187                                $discount_display_text = sprintf(__('Get %1$s at %2$s', 'yeediscounts'), $get_qty, wc_price($value));
     
    156189                                /* translators: %s: Quantity */
    157190                                $discount_display_text = sprintf(__('Get %s (Discount)', 'yeediscounts'), $get_qty);
     191                            }
     192
     193                            // BXGY Reward Description (Product/Category names)
     194                            if ($is_bxgy) {
     195                                $bxgy_adj_type = $matched_rule['buyx_gety_adjustments']['type'] ?? 'bxgy_product';
     196                                $items_list = [];
     197                                if ($bxgy_adj_type === 'bxgy_all') {
     198                                    $items_list[] = __('Any Product', 'yeediscounts');
     199                                } elseif ($bxgy_adj_type === 'bxgy_category') {
     200                                    $cat_ids = $tier['get_product'] ?? [];
     201                                    foreach ((array)$cat_ids as $cid) {
     202                                        $term = get_term($cid, 'product_cat');
     203                                        if ($term && !is_wp_error($term)) {
     204                                            $items_list[] = esc_html($term->name);
     205                                        }
     206                                    }
     207                                } else {
     208                                    $p_ids = $tier['get_product'] ?? [];
     209                                    if (count((array)$p_ids) > 3) {
     210                                        $items_list[] = __('Selected Products', 'yeediscounts');
     211                                    } else {
     212                                        foreach ((array)$p_ids as $pid) {
     213                                            $p = wc_get_product($pid);
     214                                            if ($p) {
     215                                                $items_list[] = esc_html($p->get_name());
     216                                            }
     217                                        }
     218                                    }
     219                                }
     220                                if (!empty($items_list)) {
     221                                    $reward_desc = '(' . implode(', ', $items_list) . ')';
     222                                }
     223                            }
     224                        } elseif ($is_set) {
     225                            // Set Discount Info
     226                            if ($type === 'fixed_set_price') {
     227                                $discount_display_text = sprintf(__('Set Price: %s', 'yeediscounts'), wc_price($value));
     228                            } elseif ($type === 'percentage') {
     229                                $discount_display_text = $value . '% ' . __('Off', 'yeediscounts');
     230                            } else {
     231                                $discount_display_text = wc_price($value) . ' ' . __('Off', 'yeediscounts');
    158232                            }
    159233                        } else {
     
    163237                                $discount_display_text = $value . '%';
    164238                                $discounted_price = $product_price * (1 - ($value / 100));
    165                             } elseif ($type === 'fixed') {
     239                            } elseif ($type === 'fixed' || $type === 'flat') {
    166240                                $discount_display_text = wc_price($value);
    167241                                $discounted_price = max(0, $product_price - $value);
     
    185259                            <td class="yeekit-bulk-table-td yeekit-bulk-table-discount col_index_3" data-colindex="3">
    186260                                <span class="yeekit-table-discounted-value"><?php echo wp_kses_post($discount_display_text); ?></span>
    187                                 <?php if (!$is_bogo && $discounted_price_text): ?>
     261                                <?php if ($reward_desc): ?>
     262                                    <div class="yeekit-table-reward-desc" style="font-size: 0.85em; opacity: 0.8;"><?php echo esc_html($reward_desc); ?></div>
     263                                <?php endif; ?>
     264                                <?php if (!$is_bogo && !$is_bxgy && !$is_set && $discounted_price_text): ?>
    188265                                    <span class="yeekit-table-discounted-price" style="display: none"><?php echo wp_kses_post($discounted_price_text); ?></span>
    189266                                <?php endif; ?>
  • yeediscounts/trunk/frontend/discount_bar.php

    r3490473 r3492415  
    139139
    140140                printf(
    141                     '<div class="yeekit-discount-bar %4$s" style="--yk-bar-bg: %1$s; --yk-bar-text: %2$s;">
     141                    '<div class="yeekit-discount-bar" style="--yk-bar-bg: %1$s; --yk-bar-text: %2$s;">
    142142                        <span class="yeekit-bar-message">%3$s</span>
    143143                    </div>',
  • yeediscounts/trunk/readme.txt

    r3478717 r3492415  
    33Tags: woocommerce, dynamic pricing, discounts, bulk discount
    44Tested up to: 6.9
    5 Stable tag: 1.0.5
     5Stable tag: 1.0.6
    66WC requires at least: 4.0
    77WC tested up to: 10.5
  • yeediscounts/trunk/yeediscounts.php

    r3478717 r3492415  
    55 * Requires Plugins: woocommerce
    66 * Description: Easily create and manage dynamic pricing and discount rules for your WooCommerce store.
    7  * Version: 1.0.5
     7 * Version: 1.0.6
    88 * Author: add-ons.org
    99 * Author URI: https://add-ons.org
     
    3131        include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/discount_bar.php";
    3232        include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/bulk_table.php";
    33         include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/set_table.php";
    34         include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/bxgy_table.php";
     33        // include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/set_table.php";
     34        // include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/bxgy_table.php";
    3535        include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/sale_badge.php";
    3636        include YEEKIT_DYNAMIC_DISCOUNTS_WOOCOMMERCE_PATH . "frontend/price_display.php";
Note: See TracChangeset for help on using the changeset viewer.