Changeset 3471644
- Timestamp:
- 02/28/2026 02:16:46 PM (4 weeks ago)
- Location:
- yeediscounts
- Files:
-
- 2 edited
-
tags/1.0.3/frontend/discounts.php (modified) (11 diffs)
-
trunk/frontend/discounts.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
yeediscounts/tags/1.0.3/frontend/discounts.php
r3455848 r3471644 1 1 <?php 2 if (! defined('ABSPATH')) exit; // Exit if accessed directly 2 if (!defined('ABSPATH')) 3 exit; // Exit if accessed directly 3 4 // Include helper classes 4 5 require_once __DIR__ . '/filter.php'; … … 25 26 add_filter('woocommerce_store_api_product_quantity_editable', [$this, 'restrict_quantity_input_block'], 10, 3); 26 27 //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); 28 29 //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); 30 31 // Display discount info in cart item data 31 32 add_filter('woocommerce_get_item_data', [$this, 'display_discount_meta'], 10, 2); … … 42 43 { 43 44 $product = $cart_item['data']; 44 if (!$product) return $product_subtotal; 45 if (!$product) 46 return $product_subtotal; 45 47 $qty = $cart_item['quantity']; 46 48 $price = floatval($product->get_price()); … … 60 62 foreach ($cart->get_cart() as $cart_item) { 61 63 $product = $cart_item['data']; 62 if (! $product) continue; 64 if (!$product) 65 continue; 63 66 $qty = $cart_item['quantity']; 64 67 $price = floatval($product->get_price()); … … 80 83 public function handle_fees($cart) 81 84 { 82 if (is_admin() && ! defined('DOING_AJAX')) {85 if (is_admin() && !defined('DOING_AJAX')) { 83 86 return; 84 87 } … … 89 92 if (!$rule) { 90 93 // 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'); 92 96 return; 93 97 } 94 98 if ($rule['type'] === 'yeekit_cart_discount') { 95 99 // 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']); 97 102 Yeekit_Dynamic_Discounts_Cart_Discount::handle($cart, $rule); 98 103 } 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'); 100 106 } 101 107 } … … 110 116 // Use standardized keys if available, fallback to legacy 111 117 $amount = floatval($meta['discount_value'] ?? $meta['value'] ?? $meta['amount'] ?? 0); 112 $type = $meta['discount_type'] ?? $type; // Override type if standardized key exists118 $type = $meta['discount_type'] ?? $type; // Override type if standardized key exists 113 119 } 114 120 // 2. Discount Type Label … … 119 125 $val_type_labels = [ 120 126 'free_product' => __('Free', 'yeediscounts'), 121 'percentage' => __('Percentage discount', 'yeediscounts'),122 'flat' => __('Fixed discount', 'yeediscounts'),127 'percentage' => __('Percentage discount', 'yeediscounts'), 128 'flat' => __('Fixed discount', 'yeediscounts'), 123 129 ]; 124 130 } elseif ($main_rule_type === 'yeekit_buy_x_get_y') { 125 131 $val_type_labels = [ 126 132 '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'), 130 136 ]; 131 137 } else { 132 138 $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'), 136 142 // 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'), 139 145 ]; 140 146 } … … 158 164 if ($display_value) { 159 165 $item_data[] = [ 160 'key' => __('Discount', 'yeediscounts'),161 'value' => $display_value,166 'key' => __('Discount', 'yeediscounts'), 167 'value' => $display_value, 162 168 'display' => sprintf( 163 169 '<span class="yeekit-discount-badge">%s</span>', … … 216 222 public function sync_cart_items() 217 223 { 218 if (is_admin() && ! wp_doing_ajax()) {224 if (is_admin() && !wp_doing_ajax()) { 219 225 return; 220 226 } … … 234 240 public function handle_discounts($cart) 235 241 { 236 if (is_admin() && ! defined('DOING_AJAX')) {242 if (is_admin() && !defined('DOING_AJAX')) { 237 243 return; 238 244 } -
yeediscounts/trunk/frontend/discounts.php
r3455848 r3471644 1 1 <?php 2 if (! defined('ABSPATH')) exit; // Exit if accessed directly 2 if (!defined('ABSPATH')) 3 exit; // Exit if accessed directly 3 4 // Include helper classes 4 5 require_once __DIR__ . '/filter.php'; … … 25 26 add_filter('woocommerce_store_api_product_quantity_editable', [$this, 'restrict_quantity_input_block'], 10, 3); 26 27 //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); 28 29 //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); 30 31 // Display discount info in cart item data 31 32 add_filter('woocommerce_get_item_data', [$this, 'display_discount_meta'], 10, 2); … … 42 43 { 43 44 $product = $cart_item['data']; 44 if (!$product) return $product_subtotal; 45 if (!$product) 46 return $product_subtotal; 45 47 $qty = $cart_item['quantity']; 46 48 $price = floatval($product->get_price()); … … 60 62 foreach ($cart->get_cart() as $cart_item) { 61 63 $product = $cart_item['data']; 62 if (! $product) continue; 64 if (!$product) 65 continue; 63 66 $qty = $cart_item['quantity']; 64 67 $price = floatval($product->get_price()); … … 80 83 public function handle_fees($cart) 81 84 { 82 if (is_admin() && ! defined('DOING_AJAX')) {85 if (is_admin() && !defined('DOING_AJAX')) { 83 86 return; 84 87 } … … 89 92 if (!$rule) { 90 93 // 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'); 92 96 return; 93 97 } 94 98 if ($rule['type'] === 'yeekit_cart_discount') { 95 99 // 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']); 97 102 Yeekit_Dynamic_Discounts_Cart_Discount::handle($cart, $rule); 98 103 } 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'); 100 106 } 101 107 } … … 110 116 // Use standardized keys if available, fallback to legacy 111 117 $amount = floatval($meta['discount_value'] ?? $meta['value'] ?? $meta['amount'] ?? 0); 112 $type = $meta['discount_type'] ?? $type; // Override type if standardized key exists118 $type = $meta['discount_type'] ?? $type; // Override type if standardized key exists 113 119 } 114 120 // 2. Discount Type Label … … 119 125 $val_type_labels = [ 120 126 'free_product' => __('Free', 'yeediscounts'), 121 'percentage' => __('Percentage discount', 'yeediscounts'),122 'flat' => __('Fixed discount', 'yeediscounts'),127 'percentage' => __('Percentage discount', 'yeediscounts'), 128 'flat' => __('Fixed discount', 'yeediscounts'), 123 129 ]; 124 130 } elseif ($main_rule_type === 'yeekit_buy_x_get_y') { 125 131 $val_type_labels = [ 126 132 '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'), 130 136 ]; 131 137 } else { 132 138 $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'), 136 142 // 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'), 139 145 ]; 140 146 } … … 158 164 if ($display_value) { 159 165 $item_data[] = [ 160 'key' => __('Discount', 'yeediscounts'),161 'value' => $display_value,166 'key' => __('Discount', 'yeediscounts'), 167 'value' => $display_value, 162 168 'display' => sprintf( 163 169 '<span class="yeekit-discount-badge">%s</span>', … … 216 222 public function sync_cart_items() 217 223 { 218 if (is_admin() && ! wp_doing_ajax()) {224 if (is_admin() && !wp_doing_ajax()) { 219 225 return; 220 226 } … … 234 240 public function handle_discounts($cart) 235 241 { 236 if (is_admin() && ! defined('DOING_AJAX')) {242 if (is_admin() && !defined('DOING_AJAX')) { 237 243 return; 238 244 }
Note: See TracChangeset
for help on using the changeset viewer.