46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
class Wiaas_Package {
|
|
|
|
public static function init() {
|
|
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-pricing.php';
|
|
|
|
add_filter('woocommerce_rest_prepare_product_object', array(__CLASS__, 'transform_rest_package'), 999, 3);
|
|
}
|
|
|
|
/**
|
|
* Transform package json response with wiaas information
|
|
* @param $response
|
|
* @param $package
|
|
* @param $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public static function transform_rest_package($response, $package, $request) {
|
|
$data = $response->get_data();
|
|
|
|
$data = self::_append_package_prices($data, $package, $request);
|
|
|
|
$response->set_data($data);
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Append configured package prices on package json response
|
|
* @param $data
|
|
* @param $package
|
|
* @param $request
|
|
*
|
|
* @return mixed
|
|
*/
|
|
private static function _append_package_prices($data, $package, $request) {
|
|
$package_prices = array_values(Wiaas_Package_Pricing::get_package_prices($package));
|
|
|
|
$data['prices'] = $package_prices;
|
|
|
|
return $data;
|
|
}
|
|
}
|
|
|
|
Wiaas_Package::init(); |