Add support for package payment methods and basic checkout proccess
This commit is contained in:
46
backend/app/plugins/wiaas/includes/class-wiaas-package.php
Normal file
46
backend/app/plugins/wiaas/includes/class-wiaas-package.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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();
|
||||
Reference in New Issue
Block a user