PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.2
Tiered Pricing Table for WooCommerce v2.2.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
← All changes | src/Admin/ProductManagers/VariationProductManager.php +61 -82 2.3.42.2.2 View file →
@@ -1,91 +1,70 @@
1 -<?php namespace TierPricingTable\Admin\ProductManagers;
1 +<?php
2 2
3 -use TierPricingTable\PriceManager;
4 -use WP_Post;
3 +namespace TierPricingTable\Admin\ProductManagers;
5 4
5 +use TierPricingTable\PriceManager ;
6 +use WP_Post ;
6 7 /**
7 8 * Class VariationProduct
8 9 *
9 10 * @package TierPricingTable\Admin\Product
10 11 */
11 -class VariationProductManager extends ProductManagerAbstract {
12 +class VariationProductManager extends ProductManagerAbstract
13 +{
14 + /**
15 + * Register hooks
16 + */
17 + protected function hooks()
18 + {
19 + add_action(
20 + 'woocommerce_variation_options_pricing',
21 + [ $this, 'renderPriceRules' ],
22 + 10,
23 + 3
24 + );
25 + add_action(
26 + 'woocommerce_save_product_variation',
27 + [ $this, 'updatePriceRules' ],
28 + 10,
29 + 3
30 + );
31 + }
32 +
33 + /**
34 + * Update price quantity rules for variation product
35 + *
36 + * @param int $variation_id
37 + * @param int $loop
38 + */
39 + public function updatePriceRules( $variation_id, $loop )
40 + {
41 +
42 + if ( isset( $_POST['tiered_price_fixed_quantity'][$loop] ) ) {
43 + $amounts = $_POST['tiered_price_fixed_quantity'][$loop];
44 + $prices = ( !empty($_POST['tiered_price_fixed_price'][$loop]) ? $_POST['tiered_price_fixed_price'][$loop] : [] );
45 + PriceManager::updateFixedPriceRules( $amounts, $prices, $variation_id );
46 + }
47 +
48 + }
49 +
50 + /**
51 + * Render inputs for price rules on variation
52 + *
53 + * @param int $loop
54 + * @param array $variation_data
55 + * @param WP_Post $variation
56 + */
57 + public function renderPriceRules( $loop, $variation_data, $variation )
58 + {
59 + $type = PriceManager::getPricingType( $variation->ID );
60 + $this->fileManager->includeTemplate( 'admin/add-price-rule-variation.php', [
61 + 'price_rules_fixed' => PriceManager::getFixedPriceRules( $variation->ID ),
62 + 'price_rules_percentage' => PriceManager::getPercentagePriceRules( $variation->ID ),
63 + 'i' => $loop,
64 + 'variation_data' => $variation_data,
65 + 'type' => $type,
66 + 'isFree' => $this->licence->isFree(),
67 + ] );
68 + }
12 69
13 - /**
14 - * Register hooks
15 - */
16 - protected function hooks() {
17 - add_action( 'woocommerce_variation_options_pricing', [ $this, 'renderPriceRules' ], 10, 3 );
18 - add_action( 'woocommerce_save_product_variation', [ $this, 'updatePriceRules' ], 10, 3 );
19 -
20 - if ( tpt_fs()->is__premium_only() ) {
21 - add_action( 'woocommerce_save_product_variation', [ $this, 'updatePriceRulesType__premium_only' ], 10, 3 );
22 - }
23 - }
24 -
25 - /**
26 - * Update price quantity rules for variation product
27 - *
28 - * @param int $variation_id
29 - * @param int $loop
30 - */
31 - public function updatePriceRules( $variation_id, $loop ) {
32 -
33 - if ( isset( $_POST['tiered_price_fixed_quantity'][ $loop ] ) ) {
34 - $amounts = $_POST['tiered_price_fixed_quantity'][ $loop ];
35 - $prices = ! empty( $_POST['tiered_price_fixed_price'][ $loop ] ) ? $_POST['tiered_price_fixed_price'][ $loop ] : [];
36 -
37 - PriceManager::updateFixedPriceRules( $amounts, $prices, $variation_id );
38 - }
39 -
40 - if ( tpt_fs()->is__premium_only() ) {
41 - if ( isset( $_POST['tiered_price_percent_quantity'][ $loop ] ) ) {
42 - $amounts = $_POST['tiered_price_percent_quantity'][ $loop ];
43 - $prices = ! empty( $_POST['tiered_price_percent_discount'][ $loop ] ) ? $_POST['tiered_price_percent_discount'][ $loop ] : [];
44 -
45 - PriceManager::updatePercentagePriceRules( $amounts, $prices, $variation_id );
46 - }
47 -
48 -
49 - if ( isset( $_POST['_tiered_pricing_minimum'][ $loop ] ) ) {
50 - $min = intval( $_POST['_tiered_pricing_minimum'][ $loop ] );
51 - $min = $min > 0 ? $min : 1;
52 -
53 - PriceManager::updateProductQtyMin( $variation_id, $min );
54 - }
55 - }
56 -
57 - }
58 -
59 - /**
60 - * Update product pricing type
61 - *
62 - * @param int $variation_id
63 - * @param int $loop
64 - */
65 - public function updatePriceRulesType__premium_only( $variation_id, $loop ) {
66 - if ( ! empty( $_POST['tiered_price_rules_type'][ $loop ] ) ) {
67 - PriceManager::updatePriceRulesType( $variation_id, $_POST['tiered_price_rules_type'][ $loop ] );
68 - }
69 - }
70 -
71 - /**
72 - * Render inputs for price rules on variation
73 - *
74 - * @param int $loop
75 - * @param array $variation_data
76 - * @param WP_Post $variation
77 - */
78 - public function renderPriceRules( $loop, $variation_data, $variation ) {
79 - $type = PriceManager::getPricingType( $variation->ID );
80 -
81 - $this->fileManager->includeTemplate( 'admin/add-price-rules-variation.php', [
82 - 'price_rules_fixed' => PriceManager::getFixedPriceRules( $variation->ID, 'edit' ),
83 - 'price_rules_percentage' => PriceManager::getPercentagePriceRules( $variation->ID, 'edit' ),
84 - 'i' => $loop,
85 - 'minimum' => PriceManager::getProductQtyMin( $variation->ID, 'edit' ),
86 - 'variation_data' => $variation_data,
87 - 'type' => $type,
88 - 'isFree' => $this->licence->isFree()
89 - ] );
90 - }
91 70 }