PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.3
Tiered Pricing Table for WooCommerce v2.3.3
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 / Admin / Export / Woocommerce.php

Woocommerce.php in Tiered Pricing Table for WooCommerce 2.3.3, at src/Admin/Export/Woocommerce.php

145 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TierPricingTable\Admin\Export;
4
5 use TierPricingTable\PriceManager ;
6 use WC_Product ;
7 /**
8 * Class WooCommerce Export
9 */
10 class Woocommerce
11 {
12 /**
13 * Export constructor.
14 */
15 public function __construct()
16 {
17 add_filter(
18 'woocommerce_product_export_column_names',
19 [ $this, 'addExportColumn' ],
20 1,
21 10
22 );
23 add_filter(
24 'woocommerce_product_export_product_default_columns',
25 [ $this, 'addExportColumn' ],
26 1,
27 10
28 );
29 add_filter(
30 'woocommerce_product_export_product_column_tiered_price_fixed',
31 [ $this, 'addExportFixedData' ],
32 10,
33 2
34 );
35 add_filter(
36 'woocommerce_product_export_product_column_tiered_price_percentage',
37 [ $this, 'addExportPercentageData' ],
38 10,
39 2
40 );
41 add_filter(
42 'woocommerce_product_export_product_column_tiered_price_type',
43 array( $this, 'addExportPricingTypeData' ),
44 10,
45 2
46 );
47 add_filter(
48 'woocommerce_product_export_product_column_tiered_price_minimum',
49 array( $this, 'addExportPricingMinimumData' ),
50 10,
51 2
52 );
53 }
54
55 /**
56 * Register the 'Fixed tier price' column in the exporter.
57 *
58 * @param array $columns
59 *
60 * @return array $options
61 */
62 public function addExportColumn( $columns )
63 {
64 $columns['tiered_price_fixed'] = __( 'Fixed Tiered Prices', 'tier-pricing-table' );
65 return $columns;
66 }
67
68 /**
69 * Provide the data to be exported for one item in the column.
70 *
71 * @param WC_Product $product
72 * @param string $type
73 *
74 * @return mixed $value
75 */
76 public function addExportData( $product, $type = 'fixed' )
77 {
78
79 if ( $type == 'percentage' ) {
80 $tiered_pricing = PriceManager::getPercentagePriceRules( $product->get_id() );
81 } else {
82 $tiered_pricing = PriceManager::getFixedPriceRules( $product->get_id() );
83 }
84
85 $str = '';
86 foreach ( $tiered_pricing as $quantity => $price ) {
87 $str .= $quantity . ":" . $price . ",";
88 }
89 return ( mb_strlen( $str ) > 0 ? trim( $str, ',' ) : null );
90 }
91
92 /**
93 * Export fixed pricing rules
94 *
95 * @param mixed $value
96 * @param WC_product $product
97 *
98 * @return mixed
99 */
100 public function addExportFixedData( $value, $product )
101 {
102 return $this->addExportData( $product, 'fixed' );
103 }
104
105 /**
106 * Export percentage pricing rules
107 *
108 * @param mixed $value
109 * @param WC_product $product
110 *
111 * @return mixed
112 */
113 public function addExportPercentageData( $value, $product )
114 {
115 return $this->addExportData( $product, 'percentage' );
116 }
117
118 /**
119 * Export tiered pricing type
120 *
121 * @param mixed $value
122 * @param WC_product $product
123 *
124 * @return mixed
125 */
126 public function addExportPricingTypeData( $value, $product )
127 {
128 $type = PriceManager::getPricingType( $product->get_id(), false, 'edit' );
129 return ( $type ? $type : '' );
130 }
131
132 /**
133 * Export tiered pricing minimum product quantity
134 *
135 * @param mixed $value
136 * @param WC_product $product
137 *
138 * @return mixed
139 */
140 public function addExportPricingMinimumData( $value, $product )
141 {
142 return PriceManager::getProductQtyMin( $product->get_id(), 'edit' );
143 }
144
145 }