Changeset 3490473
- Timestamp:
- 03/25/2026 04:02:14 AM (3 days ago)
- Location:
- yeediscounts
- Files:
-
- 8 edited
-
tags/1.0.5/backend/rules.php (modified) (2 diffs)
-
tags/1.0.5/frontend/discount_bar.php (modified) (4 diffs)
-
tags/1.0.5/frontend/filter.php (modified) (3 diffs)
-
tags/1.0.5/frontend/free_shipping.php (modified) (4 diffs)
-
trunk/backend/rules.php (modified) (2 diffs)
-
trunk/frontend/discount_bar.php (modified) (4 diffs)
-
trunk/frontend/filter.php (modified) (3 diffs)
-
trunk/frontend/free_shipping.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
yeediscounts/tags/1.0.5/backend/rules.php
r3478717 r3490473 221 221 * Match all conditions (AND logic) 222 222 */ 223 p rotectedstatic function match_conditions(array $conditions): bool223 public static function match_conditions(array $conditions): bool 224 224 { 225 225 foreach ($conditions as $cond) { … … 233 233 * Match a single condition 234 234 */ 235 p rotectedstatic function match_condition(array $cond): bool235 public static function match_condition(array $cond): bool 236 236 { 237 237 $type = $cond['type'] ?? ''; -
yeediscounts/tags/1.0.5/frontend/discount_bar.php
r3478717 r3490473 1 1 <?php 2 if (! defined('ABSPATH')) {2 if (!defined('ABSPATH')) { 3 3 exit; // Exit if accessed directly 4 4 } … … 48 48 $is_cart_checkout = is_cart() || is_checkout(); 49 49 50 if (! $is_product_page && !$is_cart_checkout) {50 if (!$is_product_page && !$is_cart_checkout) { 51 51 return; 52 52 } … … 127 127 // Re-use existing filter check for Product Page context relevance 128 128 $cart_item = [ 129 'product_id' => $product->get_id(),129 'product_id' => $product->get_id(), 130 130 'variation_id' => 0, 131 'data' => $product,132 'quantity' => 1131 'data' => $product, 132 'quantity' => 1 133 133 ]; 134 134 … … 140 140 printf( 141 141 '<div class="yeekit-discount-bar %4$s" style="--yk-bar-bg: %1$s; --yk-bar-text: %2$s;"> 142 <span class="yeekit-bar-icon">%5$s</span>143 142 <span class="yeekit-bar-message">%3$s</span> 144 143 </div>', 145 144 esc_attr($bg_color), 146 145 esc_attr($text_color), 147 wp_kses_post($message), 148 $is_progress ? 'yeekit-bar-progress' : 'yeekit-bar-success', 149 $is_progress ? '⚠' : '✓' // Warning icon vs Checkmark 146 wp_kses_post($message) 150 147 ); 151 148 } -
yeediscounts/tags/1.0.5/frontend/filter.php
r3478717 r3490473 1 1 <?php 2 if (! defined('ABSPATH')) exit; // Exit if accessed directly 2 if (!defined('ABSPATH')) 3 exit; // Exit if accessed directly 3 4 4 5 class Yeekit_Dynamic_Discounts_Filter … … 35 36 switch ($type) { 36 37 case 'cart_item_products': 37 $check_ids = array_map('absint', (array) $value);38 $check_ids = array_map('absint', (array) $value); 38 39 if (in_array($product_id, $check_ids) || ($variation_id && in_array($variation_id, $check_ids))) { 39 40 $match = true; … … 55 56 // format taxonomy:term_slug 56 57 $check_id = $variation_id ? $variation_id : $product_id; 57 foreach ((array) $value as $attr_str) {58 foreach ((array) $value as $attr_str) { 58 59 if (strpos($attr_str, ':') !== false) { 59 60 [$tax, $slug] = explode(':', $attr_str, 2); -
yeediscounts/tags/1.0.5/frontend/free_shipping.php
r3478717 r3490473 1 1 <?php 2 if (! defined('ABSPATH')) exit; // Exit if accessed directly 2 if (!defined('ABSPATH')) 3 exit; // Exit if accessed directly 3 4 4 5 class Yeekit_Dynamic_Discounts_Free_Shipping … … 12 13 public function handle_shipping($rates, $package) 13 14 { 14 if (is_admin() && ! defined('DOING_AJAX')) {15 if (is_admin() && !defined('DOING_AJAX')) { 15 16 return $rates; 16 17 } … … 25 26 } 26 27 27 if (empty($fs_rules)) return $rates; 28 if (empty($fs_rules)) 29 return $rates; 28 30 29 31 // Check if ANY rule matches 30 32 $is_valid = false; 31 33 foreach ($fs_rules as $rule) { 32 // Validate against CART items in the package33 // Shipping package contains 'contents' which mimics cart34 // But Filter::validate_item expects cart item structure.35 // We can iterate package contents.34 // 1. Validate against global conditions (Subtotal, User Role, etc.) 35 if (!Yeekit_Dynamic_Discounts_Rules_Manager::match_conditions($rule['conditions'] ?? [])) { 36 continue; 37 } 36 38 37 // Logic: Typically Free Shipping is "If Cart meets conditions X, Y, Z". 38 // Conditions are usually Subtotal, Quantity, or Specific Products in Cart. 39 // Our Rules Manager Filter is Item-based? Or Cart-based? 40 // "Yeekit_Dynamic_Discounts_Filter::validate_item" validates a SINGLE item. 41 // BUT for Free Shipping, we usually want "Cart has Item X" effectively. 39 // 2. Validate against CART items in the package (Product Filters) 40 // foreach ($package['contents'] as $key => $item) { 41 // if (Yeekit_Dynamic_Discounts_Filter::validate_item($item, $rule)) { 42 // $is_valid = true; 43 // break; 44 // } 45 // } 46 if ($is_valid) 47 break; 48 } 42 49 43 // Let's assume if ANY item in the cart satisfies the rule's conditions, Free Shipping applies?44 // OR do we need a special "Cart Validation" logic?45 // Current Filter.php supports: Subtotal (of item?), Quantity (of item?), Category, Product.46 // If the rule has "Subtotal greater than 100", currently it checks ITEM subtotal.47 // This might be a limitation for "Order Subtotal > 100".48 // However, usually "Filter" in this plugin context seems to select ITEMS.49 // If the filter selects at least one item, does the rule apply?50 // For now, YES. If any item matches the rule, Free Shipping is granted.51 52 foreach ($package['contents'] as $key => $item) {53 if (Yeekit_Dynamic_Discounts_Filter::validate_item($item, $rule)) {54 $is_valid = true;55 break;56 }57 }58 if ($is_valid) break;59 }60 50 if ($is_valid) { 61 51 // User requested to use the Global Setting for the Title … … 76 66 $rates[$method_id] = $new_rate; 77 67 } 78 79 68 return $rates; 80 69 } -
yeediscounts/trunk/backend/rules.php
r3477700 r3490473 221 221 * Match all conditions (AND logic) 222 222 */ 223 p rotectedstatic function match_conditions(array $conditions): bool223 public static function match_conditions(array $conditions): bool 224 224 { 225 225 foreach ($conditions as $cond) { … … 233 233 * Match a single condition 234 234 */ 235 p rotectedstatic function match_condition(array $cond): bool235 public static function match_condition(array $cond): bool 236 236 { 237 237 $type = $cond['type'] ?? ''; -
yeediscounts/trunk/frontend/discount_bar.php
r3456277 r3490473 1 1 <?php 2 if (! defined('ABSPATH')) {2 if (!defined('ABSPATH')) { 3 3 exit; // Exit if accessed directly 4 4 } … … 48 48 $is_cart_checkout = is_cart() || is_checkout(); 49 49 50 if (! $is_product_page && !$is_cart_checkout) {50 if (!$is_product_page && !$is_cart_checkout) { 51 51 return; 52 52 } … … 127 127 // Re-use existing filter check for Product Page context relevance 128 128 $cart_item = [ 129 'product_id' => $product->get_id(),129 'product_id' => $product->get_id(), 130 130 'variation_id' => 0, 131 'data' => $product,132 'quantity' => 1131 'data' => $product, 132 'quantity' => 1 133 133 ]; 134 134 … … 140 140 printf( 141 141 '<div class="yeekit-discount-bar %4$s" style="--yk-bar-bg: %1$s; --yk-bar-text: %2$s;"> 142 <span class="yeekit-bar-icon">%5$s</span>143 142 <span class="yeekit-bar-message">%3$s</span> 144 143 </div>', 145 144 esc_attr($bg_color), 146 145 esc_attr($text_color), 147 wp_kses_post($message), 148 $is_progress ? 'yeekit-bar-progress' : 'yeekit-bar-success', 149 $is_progress ? '⚠' : '✓' // Warning icon vs Checkmark 146 wp_kses_post($message) 150 147 ); 151 148 } -
yeediscounts/trunk/frontend/filter.php
r3453635 r3490473 1 1 <?php 2 if (! defined('ABSPATH')) exit; // Exit if accessed directly 2 if (!defined('ABSPATH')) 3 exit; // Exit if accessed directly 3 4 4 5 class Yeekit_Dynamic_Discounts_Filter … … 35 36 switch ($type) { 36 37 case 'cart_item_products': 37 $check_ids = array_map('absint', (array) $value);38 $check_ids = array_map('absint', (array) $value); 38 39 if (in_array($product_id, $check_ids) || ($variation_id && in_array($variation_id, $check_ids))) { 39 40 $match = true; … … 55 56 // format taxonomy:term_slug 56 57 $check_id = $variation_id ? $variation_id : $product_id; 57 foreach ((array) $value as $attr_str) {58 foreach ((array) $value as $attr_str) { 58 59 if (strpos($attr_str, ':') !== false) { 59 60 [$tax, $slug] = explode(':', $attr_str, 2); -
yeediscounts/trunk/frontend/free_shipping.php
r3453635 r3490473 1 1 <?php 2 if (! defined('ABSPATH')) exit; // Exit if accessed directly 2 if (!defined('ABSPATH')) 3 exit; // Exit if accessed directly 3 4 4 5 class Yeekit_Dynamic_Discounts_Free_Shipping … … 12 13 public function handle_shipping($rates, $package) 13 14 { 14 if (is_admin() && ! defined('DOING_AJAX')) {15 if (is_admin() && !defined('DOING_AJAX')) { 15 16 return $rates; 16 17 } … … 25 26 } 26 27 27 if (empty($fs_rules)) return $rates; 28 if (empty($fs_rules)) 29 return $rates; 28 30 29 31 // Check if ANY rule matches 30 32 $is_valid = false; 31 33 foreach ($fs_rules as $rule) { 32 // Validate against CART items in the package33 // Shipping package contains 'contents' which mimics cart34 // But Filter::validate_item expects cart item structure.35 // We can iterate package contents.34 // 1. Validate against global conditions (Subtotal, User Role, etc.) 35 if (!Yeekit_Dynamic_Discounts_Rules_Manager::match_conditions($rule['conditions'] ?? [])) { 36 continue; 37 } 36 38 37 // Logic: Typically Free Shipping is "If Cart meets conditions X, Y, Z". 38 // Conditions are usually Subtotal, Quantity, or Specific Products in Cart. 39 // Our Rules Manager Filter is Item-based? Or Cart-based? 40 // "Yeekit_Dynamic_Discounts_Filter::validate_item" validates a SINGLE item. 41 // BUT for Free Shipping, we usually want "Cart has Item X" effectively. 39 // 2. Validate against CART items in the package (Product Filters) 40 // foreach ($package['contents'] as $key => $item) { 41 // if (Yeekit_Dynamic_Discounts_Filter::validate_item($item, $rule)) { 42 // $is_valid = true; 43 // break; 44 // } 45 // } 46 if ($is_valid) 47 break; 48 } 42 49 43 // Let's assume if ANY item in the cart satisfies the rule's conditions, Free Shipping applies?44 // OR do we need a special "Cart Validation" logic?45 // Current Filter.php supports: Subtotal (of item?), Quantity (of item?), Category, Product.46 // If the rule has "Subtotal greater than 100", currently it checks ITEM subtotal.47 // This might be a limitation for "Order Subtotal > 100".48 // However, usually "Filter" in this plugin context seems to select ITEMS.49 // If the filter selects at least one item, does the rule apply?50 // For now, YES. If any item matches the rule, Free Shipping is granted.51 52 foreach ($package['contents'] as $key => $item) {53 if (Yeekit_Dynamic_Discounts_Filter::validate_item($item, $rule)) {54 $is_valid = true;55 break;56 }57 }58 if ($is_valid) break;59 }60 50 if ($is_valid) { 61 51 // User requested to use the Global Setting for the Title … … 76 66 $rates[$method_id] = $new_rate; 77 67 } 78 79 68 return $rates; 80 69 }
Note: See TracChangeset
for help on using the changeset viewer.