get_id() ) );
return 'Edit price';
}
public static function render_edit_prices_link() {
global $post;
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-package_price_editor&id=' . absint( $post->ID ) );
?>
get_type() !== 'bundle') {
return;
}
// save prices
if (! empty($_POST['wiaas_save_package_prices_nonce']) &&
wp_verify_nonce($_POST['wiaas_save_package_prices_nonce'], 'wiaas_save_package_prices')) {
self::_save_posted_package_prices($package_id);
}
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
$max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
// collect package bundle items pricing info to display
$bundled_items = $package->get_bundled_items();
$bundled_items_per_category = array();
foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product;
$product_cat = Wiaas_Product_Category::get_category($product);
if ($product_cat === 'hardware' || $product_cat === 'software') {
$product_cat = 'product';
}
$bundled_items_per_category[$product_cat] ?: array( );
$bundled_items_per_category[$product_cat][] = $bundled_item;
}
include 'views/html-package-pricing-page.php';
}
// PRIVATE HELPERS
/**
* Save posted package pricing information
*
* @param int $package_id
*/
private static function _save_posted_package_prices($package_id) {
$commission = wp_unslash($_POST['wiaas_pricing_rules_commision']);
$max_cost_margin = wp_unslash($_POST['wiaas_max_cost_margin']);
$pricing_rules = array();
$posted_pricing_rules = isset($_POST['wiaas_pricing_rules']) ? wp_unslash($_POST['wiaas_pricing_rules']) : array();
foreach ($posted_pricing_rules as $rule_type => $posted_prices) {
$posted_prices = wp_unslash($posted_prices);
$prices = array();
foreach ($posted_prices as $posted_price_type => $posted_price) {
$prices[sanitize_key($posted_price_type)] = wp_unslash($posted_price);
}
$pricing_rules[sanitize_key($rule_type)] = $prices;
}
Wiaas_Package_Pricing::set_package_prices(
wc_get_product( $package_id ),
$pricing_rules,
$commission,
$max_cost_margin);
Wiaas_Access_Management::maybe_handle_product_access($package_id, get_post($package_id));
}
}
Wiaas_Admin_Package_Pricing::init();