# tier-pricing-table/2.3.1/src/Admin/ProductManagers/VariationProductManager.php

Tiered Pricing Table for WooCommerce, version 2.3.1. 70 lines.

- Page: https://pluginprobe.com/plugins/tier-pricing-table/2.3.1/code/src/Admin/ProductManagers/VariationProductManager.php
- Raw: https://pluginprobe.com/plugins/tier-pricing-table/2.3.1/raw/src/Admin/ProductManagers/VariationProductManager.php
- Modified: 2019-03-18T08:11:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tier-pricing-table/2.3.1/code/src/Admin/ProductManagers/VariationProductManager.php#L10-L20`.

```php
<?php

namespace TierPricingTable\Admin\ProductManagers;

use  TierPricingTable\PriceManager ;
use  WP_Post ;
/**
 * Class VariationProduct
 *
 * @package TierPricingTable\Admin\Product
 */
class VariationProductManager extends ProductManagerAbstract
{
    /**
     * Register hooks
     */
    protected function hooks()
    {
        add_action(
            'woocommerce_variation_options_pricing',
            [ $this, 'renderPriceRules' ],
            10,
            3
        );
        add_action(
            'woocommerce_save_product_variation',
            [ $this, 'updatePriceRules' ],
            10,
            3
        );
    }
    
    /**
     * Update price quantity rules for variation product
     *
     * @param int $variation_id
     * @param int $loop
     */
    public function updatePriceRules( $variation_id, $loop )
    {
        
        if ( isset( $_POST['tiered_price_fixed_quantity'][$loop] ) ) {
            $amounts = $_POST['tiered_price_fixed_quantity'][$loop];
            $prices = ( !empty($_POST['tiered_price_fixed_price'][$loop]) ? $_POST['tiered_price_fixed_price'][$loop] : [] );
            PriceManager::updateFixedPriceRules( $amounts, $prices, $variation_id );
        }
    
    }
    
    /**
     * Render inputs for price rules on variation
     *
     * @param int $loop
     * @param array $variation_data
     * @param WP_Post $variation
     */
    public function renderPriceRules( $loop, $variation_data, $variation )
    {
        $type = PriceManager::getPricingType( $variation->ID );
        $this->fileManager->includeTemplate( 'admin/add-price-rule-variation.php', [
            'price_rules_fixed'      => PriceManager::getFixedPriceRules( $variation->ID ),
            'price_rules_percentage' => PriceManager::getPercentagePriceRules( $variation->ID ),
            'i'                      => $loop,
            'variation_data'         => $variation_data,
            'type'                   => $type,
            'isFree'                 => $this->licence->isFree(),
        ] );
    }

}
```
