| 1 |
<?php |
| 2 |
|
| 3 |
namespace TierPricingTable\Admin\ProductManagers; |
| 4 |
|
| 5 |
use TierPricingTable\PriceManager ; |
| 6 |
use WP_Post ; |
| 7 |
/** |
| 8 |
* Class VariationProduct |
| 9 |
* |
| 10 |
* @package TierPricingTable\Admin\Product |
| 11 |
*/ |
| 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 |
} |
| 69 |
|
| 70 |
} |