PluginProbe
Tiered Pricing Table for WooCommerce / 1.0
Tiered Pricing Table for WooCommerce v1.0
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 2.3.4 All 90 releases
tier-pricing-table / src / PriceManager.php

PriceManager.php in Tiered Pricing Table for WooCommerce 1.0, at src/PriceManager.php

38 lines 863 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable;
2
3 class PriceManager{
4
5 /**
6 * Return price rules or empty array if not exist rules
7 *
8 * @param $product_id
9 * @return array
10 */
11 static function getPriceRules($product_id)
12 {
13 $rules = get_post_meta($product_id, '_price_rules', true);
14 $rules = empty($rules) ? [] : $rules;
15
16 ksort($rules );
17
18 return $rules;
19 }
20
21 /**
22 * @param int $quantity
23 * @param int $product_id
24 * @return bool|float|int
25 */
26 public static function getPriceByRules($quantity, $product_id){
27
28 $rules = self::getPriceRules($product_id);
29
30 foreach(array_reverse($rules, true) as $_amount => $price){
31 if($_amount <= $quantity) {
32 return $price;
33 }
34 }
35
36 return false;
37 }
38 }