PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.2
Tiered Pricing Table for WooCommerce v2.3.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 2.3.4 All 90 releases
tier-pricing-table / src / Admin / Export / Woocommerce.php

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

106 lines 2.5 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 }
42
43 /**
44 * Register the 'Fixed tier price' column in the exporter.
45 *
46 * @param array $columns
47 *
48 * @return array $options
49 */
50 public function addExportColumn( $columns )
51 {
52 $columns['tiered_price_fixed'] = __( 'Fixed Tiered Prices', 'tier-pricing-table' );
53 return $columns;
54 }
55
56 /**
57 * Provide the data to be exported for one item in the column.
58 *
59 * @param WC_Product $product
60 * @param string $type
61 *
62 * @return mixed $value
63 */
64 public function addExportData( $product, $type = 'fixed' )
65 {
66
67 if ( $type == 'percentage' ) {
68 $tiered_pricing = PriceManager::getPercentagePriceRules( $product->get_id() );
69 } else {
70 $tiered_pricing = PriceManager::getFixedPriceRules( $product->get_id() );
71 }
72
73 $str = '';
74 foreach ( $tiered_pricing as $quantity => $price ) {
75 $str .= $quantity . ":" . $price . ",";
76 }
77 return ( mb_strlen( $str ) > 0 ? trim( $str, ',' ) : null );
78 }
79
80 /**
81 * Export fixed pricing rules
82 *
83 * @param mixed $value
84 * @param WC_product $product
85 *
86 * @return mixed
87 */
88 public function addExportFixedData( $value, $product )
89 {
90 return $this->addExportData( $product, 'fixed' );
91 }
92
93 /**
94 * Export percentage pricing rules
95 *
96 * @param mixed $value
97 * @param WC_product $product
98 *
99 * @return mixed
100 */
101 public function addExportPercentageData( $value, $product )
102 {
103 return $this->addExportData( $product, 'percentage' );
104 }
105
106 }