PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.1.0 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 All 92 releases
tier-pricing-table / src / Addons / ImportExport / WoocommerceExportService.php

WoocommerceExportService.php in Tiered Pricing Table for WooCommerce 8.1.0, at src/Addons/ImportExport/WoocommerceExportService.php

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