Plugin Directory

Changeset 3471644


Ignore:
Timestamp:
02/28/2026 02:16:46 PM (4 weeks ago)
Author:
addonsorg
Message:

Release new version

Location:
yeediscounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • yeediscounts/tags/1.0.3/frontend/discounts.php

    r3455848 r3471644  
    11<?php
    2 if (! defined('ABSPATH')) exit; // Exit if accessed directly
     2if (!defined('ABSPATH'))
     3    exit; // Exit if accessed directly
    34// Include helper classes
    45require_once __DIR__ . '/filter.php';
     
    2526        add_filter('woocommerce_store_api_product_quantity_editable', [$this, 'restrict_quantity_input_block'], 10, 3);
    2627        //remove cart link + block
    27         add_filter('woocommerce_cart_item_remove_link', [$this, 'restrict_remove_link'], 10, 2);
     28        //add_filter('woocommerce_cart_item_remove_link', [$this, 'restrict_remove_link'], 10, 2);
    2829        //error no remove wc_add_notice
    29         add_action('woocommerce_remove_cart_item', [$this, 'restrict_remove_link_block'], 10, 2);
     30        //add_action('woocommerce_remove_cart_item', [$this, 'restrict_remove_link_block'], 10, 2);
    3031        // Display discount info in cart item data
    3132        add_filter('woocommerce_get_item_data', [$this, 'display_discount_meta'], 10, 2);
     
    4243    {
    4344        $product = $cart_item['data'];
    44         if (!$product) return $product_subtotal;
     45        if (!$product)
     46            return $product_subtotal;
    4547        $qty = $cart_item['quantity'];
    4648        $price = floatval($product->get_price());
     
    6062        foreach ($cart->get_cart() as $cart_item) {
    6163            $product = $cart_item['data'];
    62             if (! $product) continue;
     64            if (!$product)
     65                continue;
    6366            $qty = $cart_item['quantity'];
    6467            $price = floatval($product->get_price());
     
    8083    public function handle_fees($cart)
    8184    {
    82         if (is_admin() && ! defined('DOING_AJAX')) {
     85        if (is_admin() && !defined('DOING_AJAX')) {
    8386            return;
    8487        }
     
    8992        if (!$rule) {
    9093            // Clear session if no rule matches
    91             if (WC()->session) WC()->session->__unset('yeekit_current_cart_rule_id');
     94            if (WC()->session)
     95                WC()->session->__unset('yeekit_current_cart_rule_id');
    9296            return;
    9397        }
    9498        if ($rule['type'] === 'yeekit_cart_discount') {
    9599            // Store ID for Order creation tracking
    96             if (WC()->session) WC()->session->set('yeekit_current_cart_rule_id', $rule['id']);
     100            if (WC()->session)
     101                WC()->session->set('yeekit_current_cart_rule_id', $rule['id']);
    97102            Yeekit_Dynamic_Discounts_Cart_Discount::handle($cart, $rule);
    98103        } else {
    99             if (WC()->session) WC()->session->__unset('yeekit_current_cart_rule_id');
     104            if (WC()->session)
     105                WC()->session->__unset('yeekit_current_cart_rule_id');
    100106        }
    101107    }
     
    110116            // Use standardized keys if available, fallback to legacy
    111117            $amount = floatval($meta['discount_value'] ?? $meta['value'] ?? $meta['amount'] ?? 0);
    112             $type   = $meta['discount_type'] ?? $type; // Override type if standardized key exists
     118            $type = $meta['discount_type'] ?? $type; // Override type if standardized key exists
    113119        }
    114120        // 2. Discount Type Label
     
    119125            $val_type_labels = [
    120126                'free_product' => __('Free', 'yeediscounts'),
    121                 'percentage'   => __('Percentage discount', 'yeediscounts'),
    122                 'flat'         => __('Fixed discount', 'yeediscounts'),
     127                'percentage' => __('Percentage discount', 'yeediscounts'),
     128                'flat' => __('Fixed discount', 'yeediscounts'),
    123129            ];
    124130        } elseif ($main_rule_type === 'yeekit_buy_x_get_y') {
    125131            $val_type_labels = [
    126132                'free_product' => __('Free', 'yeediscounts'),
    127                 'percentage'   => __('Percentage discount', 'yeediscounts'),
    128                 'flat'         => __('Fixed discount', 'yeediscounts'),
    129                 'fixed_price'  => __('Fixed Price per item', 'yeediscounts'),
     133                'percentage' => __('Percentage discount', 'yeediscounts'),
     134                'flat' => __('Fixed discount', 'yeediscounts'),
     135                'fixed_price' => __('Fixed Price per item', 'yeediscounts'),
    130136            ];
    131137        } else {
    132138            $val_type_labels = [
    133                 'percentage'      => __('Percentage discount', 'yeediscounts'),
    134                 'fixed'           => __('Fixed discount', 'yeediscounts'),
    135                 'fixed_price'     => __('Fixed price per item', 'yeediscounts'),
     139                'percentage' => __('Percentage discount', 'yeediscounts'),
     140                'fixed' => __('Fixed discount', 'yeediscounts'),
     141                'fixed_price' => __('Fixed price per item', 'yeediscounts'),
    136142                // Fallbacks if rule ID lookup fails or specific BOGO types leak through
    137                 'flat'            => __('Fixed discount', 'yeediscounts'),
    138                 'free_product'    => __('Free', 'yeediscounts'),
     143                'flat' => __('Fixed discount', 'yeediscounts'),
     144                'free_product' => __('Free', 'yeediscounts'),
    139145            ];
    140146        }
     
    158164        if ($display_value) {
    159165            $item_data[] = [
    160                 'key'     => __('Discount', 'yeediscounts'),
    161                 'value'   => $display_value,
     166                'key' => __('Discount', 'yeediscounts'),
     167                'value' => $display_value,
    162168                'display' => sprintf(
    163169                    '<span class="yeekit-discount-badge">%s</span>',
     
    216222    public function sync_cart_items()
    217223    {
    218         if (is_admin() && ! wp_doing_ajax()) {
     224        if (is_admin() && !wp_doing_ajax()) {
    219225            return;
    220226        }
     
    234240    public function handle_discounts($cart)
    235241    {
    236         if (is_admin() && ! defined('DOING_AJAX')) {
     242        if (is_admin() && !defined('DOING_AJAX')) {
    237243            return;
    238244        }
  • yeediscounts/trunk/frontend/discounts.php

    r3455848 r3471644  
    11<?php
    2 if (! defined('ABSPATH')) exit; // Exit if accessed directly
     2if (!defined('ABSPATH'))
     3    exit; // Exit if accessed directly
    34// Include helper classes
    45require_once __DIR__ . '/filter.php';
     
    2526        add_filter('woocommerce_store_api_product_quantity_editable', [$this, 'restrict_quantity_input_block'], 10, 3);
    2627        //remove cart link + block
    27         add_filter('woocommerce_cart_item_remove_link', [$this, 'restrict_remove_link'], 10, 2);
     28        //add_filter('woocommerce_cart_item_remove_link', [$this, 'restrict_remove_link'], 10, 2);
    2829        //error no remove wc_add_notice
    29         add_action('woocommerce_remove_cart_item', [$this, 'restrict_remove_link_block'], 10, 2);
     30        //add_action('woocommerce_remove_cart_item', [$this, 'restrict_remove_link_block'], 10, 2);
    3031        // Display discount info in cart item data
    3132        add_filter('woocommerce_get_item_data', [$this, 'display_discount_meta'], 10, 2);
     
    4243    {
    4344        $product = $cart_item['data'];
    44         if (!$product) return $product_subtotal;
     45        if (!$product)
     46            return $product_subtotal;
    4547        $qty = $cart_item['quantity'];
    4648        $price = floatval($product->get_price());
     
    6062        foreach ($cart->get_cart() as $cart_item) {
    6163            $product = $cart_item['data'];
    62             if (! $product) continue;
     64            if (!$product)
     65                continue;
    6366            $qty = $cart_item['quantity'];
    6467            $price = floatval($product->get_price());
     
    8083    public function handle_fees($cart)
    8184    {
    82         if (is_admin() && ! defined('DOING_AJAX')) {
     85        if (is_admin() && !defined('DOING_AJAX')) {
    8386            return;
    8487        }
     
    8992        if (!$rule) {
    9093            // Clear session if no rule matches
    91             if (WC()->session) WC()->session->__unset('yeekit_current_cart_rule_id');
     94            if (WC()->session)
     95                WC()->session->__unset('yeekit_current_cart_rule_id');
    9296            return;
    9397        }
    9498        if ($rule['type'] === 'yeekit_cart_discount') {
    9599            // Store ID for Order creation tracking
    96             if (WC()->session) WC()->session->set('yeekit_current_cart_rule_id', $rule['id']);
     100            if (WC()->session)
     101                WC()->session->set('yeekit_current_cart_rule_id', $rule['id']);
    97102            Yeekit_Dynamic_Discounts_Cart_Discount::handle($cart, $rule);
    98103        } else {
    99             if (WC()->session) WC()->session->__unset('yeekit_current_cart_rule_id');
     104            if (WC()->session)
     105                WC()->session->__unset('yeekit_current_cart_rule_id');
    100106        }
    101107    }
     
    110116            // Use standardized keys if available, fallback to legacy
    111117            $amount = floatval($meta['discount_value'] ?? $meta['value'] ?? $meta['amount'] ?? 0);
    112             $type   = $meta['discount_type'] ?? $type; // Override type if standardized key exists
     118            $type = $meta['discount_type'] ?? $type; // Override type if standardized key exists
    113119        }
    114120        // 2. Discount Type Label
     
    119125            $val_type_labels = [
    120126                'free_product' => __('Free', 'yeediscounts'),
    121                 'percentage'   => __('Percentage discount', 'yeediscounts'),
    122                 'flat'         => __('Fixed discount', 'yeediscounts'),
     127                'percentage' => __('Percentage discount', 'yeediscounts'),
     128                'flat' => __('Fixed discount', 'yeediscounts'),
    123129            ];
    124130        } elseif ($main_rule_type === 'yeekit_buy_x_get_y') {
    125131            $val_type_labels = [
    126132                'free_product' => __('Free', 'yeediscounts'),
    127                 'percentage'   => __('Percentage discount', 'yeediscounts'),
    128                 'flat'         => __('Fixed discount', 'yeediscounts'),
    129                 'fixed_price'  => __('Fixed Price per item', 'yeediscounts'),
     133                'percentage' => __('Percentage discount', 'yeediscounts'),
     134                'flat' => __('Fixed discount', 'yeediscounts'),
     135                'fixed_price' => __('Fixed Price per item', 'yeediscounts'),
    130136            ];
    131137        } else {
    132138            $val_type_labels = [
    133                 'percentage'      => __('Percentage discount', 'yeediscounts'),
    134                 'fixed'           => __('Fixed discount', 'yeediscounts'),
    135                 'fixed_price'     => __('Fixed price per item', 'yeediscounts'),
     139                'percentage' => __('Percentage discount', 'yeediscounts'),
     140                'fixed' => __('Fixed discount', 'yeediscounts'),
     141                'fixed_price' => __('Fixed price per item', 'yeediscounts'),
    136142                // Fallbacks if rule ID lookup fails or specific BOGO types leak through
    137                 'flat'            => __('Fixed discount', 'yeediscounts'),
    138                 'free_product'    => __('Free', 'yeediscounts'),
     143                'flat' => __('Fixed discount', 'yeediscounts'),
     144                'free_product' => __('Free', 'yeediscounts'),
    139145            ];
    140146        }
     
    158164        if ($display_value) {
    159165            $item_data[] = [
    160                 'key'     => __('Discount', 'yeediscounts'),
    161                 'value'   => $display_value,
     166                'key' => __('Discount', 'yeediscounts'),
     167                'value' => $display_value,
    162168                'display' => sprintf(
    163169                    '<span class="yeekit-discount-badge">%s</span>',
     
    216222    public function sync_cart_items()
    217223    {
    218         if (is_admin() && ! wp_doing_ajax()) {
     224        if (is_admin() && !wp_doing_ajax()) {
    219225            return;
    220226        }
     
    234240    public function handle_discounts($cart)
    235241    {
    236         if (is_admin() && ! defined('DOING_AJAX')) {
     242        if (is_admin() && !defined('DOING_AJAX')) {
    237243            return;
    238244        }
Note: See TracChangeset for help on using the changeset viewer.