| 1 |
<?php |
| 2 |
|
| 3 |
namespace TierPricingTable\Admin\ProductManagers; |
| 4 |
|
| 5 |
use TierPricingTable\PriceManager ; |
| 6 |
use WC_Product ; |
| 7 |
/** |
| 8 |
* Class SimpleProductManager |
| 9 |
* |
| 10 |
* @package TierPricingTable\Admin\Product |
| 11 |
*/ |
| 12 |
class SimpleProductManager extends ProductManagerAbstract |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Register hooks |
| 16 |
*/ |
| 17 |
protected function hooks() |
| 18 |
{ |
| 19 |
add_action( 'woocommerce_product_options_pricing', [ $this, 'renderPriceRules' ] ); |
| 20 |
add_action( 'save_post_product', [ $this, 'updatePriceRules' ] ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Update price quantity rules for simple product |
| 25 |
* |
| 26 |
* @param int $product_id |
| 27 |
*/ |
| 28 |
public function updatePriceRules( $product_id ) |
| 29 |
{ |
| 30 |
|
| 31 |
if ( isset( $_POST['tiered_price_fixed_quantity'] ) ) { |
| 32 |
$amounts = $_POST['tiered_price_fixed_quantity']; |
| 33 |
$prices = ( !empty($_POST['tiered_price_fixed_price']) ? $_POST['tiered_price_fixed_price'] : [] ); |
| 34 |
PriceManager::updateFixedPriceRules( $amounts, $prices, $product_id ); |
| 35 |
} |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Render inputs for price rules on simple product |
| 41 |
* |
| 42 |
* @global WC_Product $product_object |
| 43 |
*/ |
| 44 |
public function renderPriceRules() |
| 45 |
{ |
| 46 |
global $product_object ; |
| 47 |
|
| 48 |
if ( $product_object instanceof WC_Product ) { |
| 49 |
$type = PriceManager::getPricingType( $product_object->get_id() ); |
| 50 |
$this->fileManager->includeTemplate( 'admin/add-price-rule-simple.php', [ |
| 51 |
'price_rules_fixed' => PriceManager::getFixedPriceRules( $product_object->get_id() ), |
| 52 |
'price_rules_percentage' => PriceManager::getPercentagePriceRules( $product_object->get_id() ), |
| 53 |
'type' => $type, |
| 54 |
'isFree' => $this->licence->isFree(), |
| 55 |
] ); |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
} |