76 lines
2.8 KiB
PHP
76 lines
2.8 KiB
PHP
<?php
|
|
|
|
class Wiaas_Shop {
|
|
|
|
public static function init() {
|
|
|
|
// registers special prices taxonomy that will enable package search based on
|
|
// set and visible price types (default and customer specific ones)
|
|
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_prices_taxonomy'));
|
|
|
|
// update prices search terms for package after prices extras have been updated
|
|
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
|
|
}
|
|
|
|
/**
|
|
* Register special prices taxonomy to enable search of packages by prices inside every shop
|
|
*/
|
|
public static function register_prices_taxonomy() {
|
|
$args = array(
|
|
'hierarchical' => false,
|
|
'query_var' => true,
|
|
'rewrite' => false,
|
|
'public' => true,
|
|
'capabilities' => array(
|
|
'manage_terms' => 'manage_wiaas_package_price_terms',
|
|
'edit_terms' => 'edit_wiaas_package_price_terms',
|
|
'delete_terms' => 'delete_wiaas_package_price_terms',
|
|
'assign_terms' => 'assign_wiaas_package_price_terms',
|
|
),
|
|
);
|
|
|
|
register_taxonomy( '_wiaas_shop_prices', array( 'product' ), $args );
|
|
}
|
|
|
|
/**
|
|
* Relate pricing search terms to package so customer can retrieve packages with default or
|
|
* their own specific prices.
|
|
* (ex: Package which will be hidden fro Customer 1 because default price
|
|
* is hidden can be visible for Customer 2 because specific prices are set for that customer)
|
|
*
|
|
* @param int $owner_id
|
|
* @param int $package_id
|
|
* @param array $cl_extras {
|
|
* $extra_price_payment_type => {
|
|
* @type bool visible Indicates if payment type is visible to customer
|
|
* }
|
|
* }
|
|
* @param array $old_cl_extras {
|
|
* $extra_price_payment_type => {
|
|
* @type bool visible Indicates if payment type is visible to customer
|
|
* }
|
|
* }
|
|
*/
|
|
public static function update_package_prices_search_terms($owner_id, $package_id, $cl_extras, $old_cl_extras) {
|
|
// remove pricing terms for previous prices
|
|
if (! empty($old_cl_extras)) {
|
|
|
|
$old_visible_price_types = array_keys(wp_list_filter($old_cl_extras, array( 'visible' => true )));
|
|
|
|
$old_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $old_visible_price_types);
|
|
|
|
wp_remove_object_terms($package_id, $old_terms_names, '_wiaas_shop_prices');
|
|
}
|
|
|
|
// get visible price types set by shop owner (commercial lead)
|
|
$visible_price_types = array_keys(wp_list_filter($cl_extras, array('visible' => true)));
|
|
|
|
$new_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $visible_price_types);
|
|
|
|
// create term for every visible pricing type and link them to package so package can be queried
|
|
wp_set_object_terms($package_id, $new_terms_names, '_wiaas_shop_prices');
|
|
}
|
|
}
|
|
|
|
Wiaas_Shop::init();
|