PluginProbe
Whols – Wholesale Prices and B2B Store Solution for WooCommerce / trunk
Whols – Wholesale Prices and B2B Store Solution for WooCommerce vtrunk
2.4.12 2.4.11 trunk 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 55 releases
whols / includes / Compatibility.php

Compatibility.php in Whols – Wholesale Prices and B2B Store Solution for WooCommerce trunk, at includes/Compatibility.php

126 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Whols;
3
4 /**
5 * Compatibility Class
6 */
7 class Compatibility {
8 /**
9 * Constructor
10 */
11 public function __construct() {
12 // Fibosearch compatibility
13 add_filter('dgwt/wcas/search_query/args', array($this, 'fibosearch_search_query_args'), 10, 2);
14
15 // Compatible with CURCY - Multi Currency by VillaTheme
16 add_filter( 'whols_override_wholesale_price', array($this, 'curcy_override_wholesale_price'), 10, 2);
17
18 // WooCommerce Product Export - fix empty quantities
19 add_filter('woocommerce_product_export_meta_value', array($this, 'fix_export_quantity'), 10, 4);
20 }
21
22 public function fibosearch_search_query_args($args) {
23 if( !whols_is_wholesaler() ) {
24 $args['meta_query'][] = array(
25 'key' => '_whols_mark_this_product_as_wholesale_only',
26 'value' => 'yes',
27 'compare' => '!=',
28 );
29 }
30
31 return $args;
32 }
33
34 public function curcy_override_wholesale_price( $price_arr ) {
35 $currentCurrencyRate = $this->curcy_get_currency_rate();
36
37 if( $currentCurrencyRate ){
38 if( !empty( $price_arr['price']) ){
39 $price_arr['price'] = floatval($price_arr['price']) * $currentCurrencyRate;
40 }
41
42 if( !empty( $price_arr['min_price']) ){
43 $price_arr['min_price'] = floatval($price_arr['min_price']) * $currentCurrencyRate;
44 }
45
46 if( !empty( $price_arr['max_price']) ){
47 $price_arr['max_price'] = floatval($price_arr['max_price']) * $currentCurrencyRate;
48 }
49 }
50
51 return $price_arr;
52 }
53
54 public function curcy_get_currency_rate(){
55 $currentCurrencyRate = null;
56
57 // For free version
58 if(class_exists('\WOOMULTI_CURRENCY_F_Data')) {
59 $multiCurrencySettings = \WOOMULTI_CURRENCY_F_Data::get_ins();
60 $wmcCurrencies = $multiCurrencySettings->get_list_currencies();
61 $currentCurrency = $multiCurrencySettings->get_current_currency();
62 $currentCurrencyRate = floatval( $wmcCurrencies[ $currentCurrency ]['rate'] );
63 }
64
65 // For pro version
66 if(class_exists('\WOOMULTI_CURRENCY_Data')) {
67 $multiCurrencySettings = \WOOMULTI_CURRENCY_Data::get_ins();
68 $wmcCurrencies = $multiCurrencySettings->get_list_currencies();
69 $currentCurrency = $multiCurrencySettings->get_current_currency();
70 $currentCurrencyRate = floatval( $wmcCurrencies[ $currentCurrency ]['rate'] );
71 }
72
73 return $currentCurrencyRate;
74 }
75
76 /**
77 * Fix empty quantities in wholesale pricing meta during export.
78 *
79 * @param mixed $value Meta value.
80 * @param object $meta Meta object.
81 * @param object $product Product object.
82 * @param array $row Export row data.
83 * @return mixed
84 */
85 public function fix_export_quantity($value, $meta, $product, $row) {
86 if (empty($value)) {
87 return $value;
88 }
89
90 // Type 1: Single role pricing (format: price:quantity)
91 if ($meta->key === '_whols_price_type_1_properties') {
92 $parts = explode(':', $value);
93 if (count($parts) >= 1) {
94 $price = $parts[0];
95 $quantity = isset($parts[1]) && $parts[1] !== '' ? $parts[1] : '1';
96 return $price . ':' . $quantity;
97 }
98 }
99
100 // Type 2: Multiple role pricing (format: role:price:quantity;)
101 if ($meta->key === '_whols_price_type_2_properties') {
102 $rules = explode(';', $value);
103 $fixed_rules = array();
104
105 foreach ($rules as $rule) {
106 $rule = trim($rule);
107 if (empty($rule)) {
108 continue;
109 }
110
111 $parts = explode(':', $rule);
112 if (count($parts) >= 2) {
113 $role = $parts[0];
114 $price = $parts[1];
115 $quantity = isset($parts[2]) && $parts[2] !== '' ? $parts[2] : '1';
116 $fixed_rules[] = $role . ':' . $price . ':' . $quantity;
117 }
118 }
119
120 return !empty($fixed_rules) ? implode(';', $fixed_rules) . ';' : $value;
121 }
122
123 return $value;
124 }
125 }
126