400 ) ); } } return null; } /** * Filter woocommerce REST API query so only valid wiaas packages are returned to the customer * * @param $args * @param $request * * @return mixed */ public static function filter_packages($args, $request) { if ( empty($args['tax_query']) ){ $args['tax_query'] = array(); } // Retrieve only packages with available package status $args['tax_query'][] = array( 'taxonomy' => 'package_status', 'field' => 'name', 'terms' => Wiaas_Package_Status::AVAILABLE ); /** * Retrieve packages that satisfy one of two: * * 1) Package has at least one visible customer specific price set (for current customer) * 2) Package has at least one visible default price set and not customer specific prices set (for current customer) * * This approach enables us that if package has specific prices set for current customer only those prices * are taken into account and default ones are ignored. * Only if package has no specific prices for current customer default prices are taken into account. * */ $shop_id = absint($request['shop_id']); $customer_id = wiaas_get_current_user_organization_id(); $default_price_search_term = '_' . $shop_id . '_default'; $customer_visible_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_visible'; $customer_hidden_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_hidden'; $args['tax_query'][] = array( 'relation' => 'OR', array( 'taxonomy' => '_wiaas_shop_prices', 'terms' => $customer_visible_price_search_term, 'field' => 'slug' ), array( array( 'taxonomy' => '_wiaas_shop_prices', 'terms' => $default_price_search_term, 'field' => 'slug' ), array( 'taxonomy' => '_wiaas_shop_prices', 'terms' => $customer_hidden_price_search_term, 'field' => 'slug', 'operator' => 'NOT IN' ) ) ); return $args; } } Wiaas_WC_Package_API_Integration::init();