PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
← All changes | src/Services/DebugService.php +28 -27 6.1.0 → 8.0.2 View file →
@@ -10,44 +10,44 @@
10 10 use TierPricingTable\PriceManager;
11 11 use TierPricingTable\PricingRule;
12 12
13 13 class DebugService {
14 -
14 +
15 15 public function __construct() {
16 -
16 +
17 17 if ( ServiceContainer::getInstance()->getSettings()->get( 'debug_enabled', 'no' ) !== 'yes' ) {
18 18 return;
19 19 }
20 -
20 +
21 21 add_action( 'woocommerce_after_cart_item_name', function ( $cartItem ) {
22 -
22 +
23 23 if ( ! ( $cartItem['data'] instanceof \WC_Product ) ) {
24 24 return;
25 25 }
26 -
26 +
27 27 $pricingRule = PriceManager::getPricingRule( $cartItem['data']->get_id() );
28 -
28 +
29 29 $this->formatPricingRule( $pricingRule, $cartItem );
30 30 } );
31 -
31 +
32 32 add_action( 'tiered_pricing_table/before_rendering_tiered_pricing/inner',
33 - function ( PricingRule $pricingRule ) {
34 - $this->formatPricingRule( $pricingRule );
35 - } );
33 + function ( PricingRule $pricingRule ) {
34 + $this->formatPricingRule( $pricingRule );
35 + } );
36 36 }
37 -
37 +
38 38 protected function getPricingRuleData( PricingRule $pricingRule, ?array $cartItem = null ): array {
39 -
39 +
40 40 switch ( $pricingRule->provider ) {
41 41 case 'global-rules':
42 42 $globalRuleId = $pricingRule->providerData['rule_id'] ?? 'N\A';
43 43 $data['provider'] = sprintf( '<a href="%s">%s</a>', get_edit_post_link( $globalRuleId ),
44 - "Global rule ($globalRuleId)" );
44 + "Global rule ($globalRuleId)" );
45 45 break;
46 46 case 'category-rules':
47 47 $categoryId = $pricingRule->providerData['category_id'] ?? 'N\A';
48 48 $data['provider'] = sprintf( '<a href="%s">%s</a>', get_edit_term_link( $categoryId ),
49 - "DEPRECATED Category rule ($categoryId)" );
49 + "DEPRECATED Category rule ($categoryId)" );
50 50 break;
51 51 case 'role-based':
52 52 $role = $pricingRule->providerData['role'] ?? 'N\A';
53 53 $data['provider'] = "Role-based rule ($role)";
@@ -59,39 +59,40 @@
59 59 $provider = $pricingRule->provider ?? 'N\A';
60 60 $data['provider'] = "Undefined provider ($provider)";
61 61 }
62 62
63 - $data['minimum'] = $pricingRule->getMinimum() ? $pricingRule->getMinimum() : 'N/A';
64 - $data['maximum'] = ! empty( $pricingRule->data['maximum_quantity'] ) ? $pricingRule->data['maximum_quantity'] : 'N/A';
65 - $data['quantity_step'] = ! empty( $pricingRule->data['group_of_quantity'] ) ? $pricingRule->data['group_of_quantity'] : 'N/A';
66 -
63 + $data['minimum'] = $pricingRule->getMinimum() ? $pricingRule->getMinimum() : 'N/A';
64 + $data['minimum_mix_and_match'] = $pricingRule->isMixAndMatchMinQuantity() ? 'Yes' : 'No';
65 + $data['maximum'] = ! empty( $pricingRule->data['maximum_quantity'] ) ? $pricingRule->data['maximum_quantity'] : 'N/A';
66 + $data['quantity_step'] = ! empty( $pricingRule->data['group_of_quantity'] ) ? $pricingRule->data['group_of_quantity'] : 'N/A';
67 +
67 68 $data['pricing_type'] = $pricingRule->getType();
68 69 $data['rules'] = '-';
69 -
70 +
70 71 if ( ! empty( $pricingRule->getRules() ) ) {
71 72 $data['rules'] = '';
72 -
73 +
73 74 foreach ( $pricingRule->getRules() as $quantity => $price ) {
74 75 $data['rules'] .= $quantity . ':' . $price . ',';
75 76 }
76 77 }
77 -
78 +
78 79 if ( $cartItem ) {
79 80 $data['total_in_cart'] = ! empty( $cartItem['tiered_pricing_data']['total_item_quantity'] ) ? $cartItem['tiered_pricing_data']['total_item_quantity'] : 'undefined';
80 81 } else {
81 82 $data['total_in_cart'] = 'N\A';
82 83 }
83 -
84 +
84 85 $data['custom_regular_price'] = ! empty( $pricingRule->pricingData['regular_price'] ) ? $pricingRule->pricingData['regular_price'] : 'N\A';
85 86 $data['custom_sale_price'] = ! empty( $pricingRule->pricingData['sale_price'] ) ? $pricingRule->pricingData['sale_price'] : 'N\A';
86 87 $data['discount'] = ! empty( $pricingRule->pricingData['discount'] ) ? $pricingRule->pricingData['discount'] : 'N\A';
87 88 $data['custom_pricing_type'] = ! empty( $pricingRule->pricingData['pricing_type'] ) ? $pricingRule->pricingData['pricing_type'] : 'N\A';
88 -
89 +
89 90 return $data;
90 91 }
91 -
92 +
92 93 protected function formatPricingRule( PricingRule $pricingRule, ?array $cartItem = null ) {
93 -
94 +
94 95 $data = $this->getPricingRuleData( $pricingRule, $cartItem );
95 96 ?>
96 97
97 98 <div>
@@ -114,9 +115,9 @@
114 115 <?php endforeach; ?>
115 116 </tbody>
116 117 </table>
117 118 </div>
118 -
119 +
119 120 <?php if ( ! empty( $pricingRule->getPricingLog() ) ) : ?>
120 121 <small>
121 122 Pricing Log
122 123 <ol>
@@ -125,8 +126,8 @@
125 126 <?php endforeach; ?>
126 127 </ol>
127 128 </small>
128 129 <?php endif; ?>
129 -
130 +
130 131 <?php
131 132 }
132 133 }