PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.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 2.3.3 All 91 releases
tier-pricing-table / src / Addons / RoleBasedPricing / Export / RoleBasedPricingExport.php

RoleBasedPricingExport.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Addons/RoleBasedPricing/Export/RoleBasedPricingExport.php

142 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\RoleBasedPricing\Export;
2
3 use TierPricingTable\Addons\RoleBasedPricing\RoleBasedPriceManager;
4 use TierPricingTable\TierPricingTablePlugin;
5 use WC_Product;
6
7 class RoleBasedPricingExport {
8
9 /**
10 * Export constructor.
11 */
12 public function __construct() {
13 add_filter( 'woocommerce_product_export_column_names', array( $this, 'addExportColumn' ), 999 );
14 add_filter( 'woocommerce_product_export_product_default_columns', array( $this, 'addExportColumn' ), 999 );
15
16 add_action( 'init', function () {
17
18 if ( ! is_admin() ) {
19 return;
20 }
21
22 $columns = array();
23
24 foreach ( wp_roles()->roles as $WPRole => $role_data ) {
25
26 $columns[] = array(
27 'column_title' => $WPRole . '_tiered_price_pricing_type',
28 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
29 return RoleBasedPriceManager::getProductPricingType( $product->get_id(), $WPRole, 'edit' );
30 },
31 );
32
33 $columns[] = array(
34 'column_title' => $WPRole . '_tiered_price_regular_price',
35 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
36 return RoleBasedPriceManager::getProductRegularRolePrice( $product->get_id(), $WPRole, 'edit' );
37 },
38 );
39
40 $columns[] = array(
41 'column_title' => $WPRole . '_tiered_price_sale_price',
42 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
43 return RoleBasedPriceManager::getProductSaleRolePrice( $product->get_id(), $WPRole, 'edit' );
44 },
45 );
46
47 $columns[] = array(
48 'column_title' => $WPRole . '_tiered_price_discount',
49 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
50 return RoleBasedPriceManager::getProductDiscount( $product->get_id(), $WPRole, 'edit' );
51 },
52 );
53
54 $columns[] = array(
55 'column_title' => $WPRole . '_tiered_price_fixed',
56 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
57 $fixedRules = RoleBasedPriceManager::getPriceRules( $product->get_id(), $WPRole, 'fixed' );
58
59 $str = '';
60 $separator = TierPricingTablePlugin::getRulesSeparator();
61
62 foreach ( $fixedRules as $quantity => $price ) {
63 $str .= $quantity . ':' . $price . $separator;
64 }
65
66 return mb_strlen( $str ) > 0 ? trim( $str, $separator ) : null;
67 },
68 );
69
70 $columns[] = array(
71 'column_title' => $WPRole . '_tiered_price_percentage',
72 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
73 $fixedRules = RoleBasedPriceManager::getPriceRules( $product->get_id(), $WPRole, 'percentage' );
74
75 $str = '';
76 $separator = TierPricingTablePlugin::getRulesSeparator();
77
78 foreach ( $fixedRules as $quantity => $discount ) {
79 $str .= $quantity . ':' . $discount . $separator;
80 }
81
82 return mb_strlen( $str ) > 0 ? trim( $str, $separator ) : null;
83 },
84 );
85
86 $columns[] = array(
87 'column_title' => $WPRole . '_tiered_price_type',
88 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
89 return RoleBasedPriceManager::getPricingType( $product->get_id(), $WPRole, 'edit' );
90 },
91 );
92
93 $columns[] = array(
94 'column_title' => $WPRole . '_tiered_price_minimum',
95 'export_callback' => function ( $value, WC_Product $product ) use ( $WPRole ) {
96 return RoleBasedPriceManager::getProductQtyMin( $product->get_id(), $WPRole, 'edit' );
97 },
98 );
99 }
100
101 foreach ( $columns as $column ) {
102 add_filter( 'woocommerce_product_export_product_column_' . $column['column_title'],
103 $column['export_callback'], 20, 2 );
104 }
105
106 } );
107 }
108
109 /**
110 * Register the 'Fixed tiered price' column in the exporter.
111 */
112 public function addExportColumn( array $columns ): array {
113
114 global $wp_roles;
115
116 foreach ( wp_roles()->roles as $WPRole => $role_data ) {
117
118 $roleName = isset( $wp_roles->role_names[ $WPRole ] ) ? translate_user_role( $wp_roles->role_names[ $WPRole ] ) : $WPRole;
119
120 $columns[ $WPRole . '_tiered_price_pricing_type' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Regular pricing type',
121 'tier-pricing-table' );
122 $columns[ $WPRole . '_tiered_price_regular_price' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Regular price',
123 'tier-pricing-table' );
124 $columns[ $WPRole . '_tiered_price_sale_price' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Sale price',
125 'tier-pricing-table' );
126 $columns[ $WPRole . '_tiered_price_discount' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Percentage discount',
127 'tier-pricing-table' );
128 $columns[ $WPRole . '_tiered_price_fixed' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Fixed pricing rules',
129 'tier-pricing-table' );
130 $columns[ $WPRole . '_tiered_price_percentage' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Percentage pricing rules',
131 'tier-pricing-table' );
132 $columns[ $WPRole . '_tiered_price_type' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Tiered pricing type',
133 'tier-pricing-table' );
134 $columns[ $WPRole . '_tiered_price_minimum' ] = 'Tiered Pricing — ' . ' [' . $roleName . '] ' . __( 'Minimum order quantity',
135 'tier-pricing-table' );
136 }
137
138 return $columns;
139 }
140 }
141
142