This hooks allows to make compatible a woocommerce filters plugins with WOOT.
Lets review filter adaptation for WOOF (as an example):
- into the file functions.php of the current wordpress theme add next code:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960add_filter("woot_profile_extend", function($profile, $action, $shortcode_args) {if ('woot_woocommerce_tables' === $action) {if (isset($shortcode_args['filter_provider'])) {if ($shortcode_args['filter_provider'] === 'woof') {if (array_key_exists('WOOF', $GLOBALS)) {global $WOOF;$profile[0]['filter_provider'] = 'woof';$profile[0]['filter_data'] = $WOOF->get_request_data();add_action('woot_filter_provider_woof', function ($args, $filter_data) {if (!is_array($filter_data)) {$filter_data = json_decode($filter_data, true);}if (!empty($filter_data) AND is_array($filter_data)) {foreach (array_keys($filter_data) as $key) {if (is_integer($key)) {unset($filter_data[$key]);}}}//***//here is clean WOOF functionalityglobal $WOOF;if ((isset($filter_data[$WOOF->get_swoof_search_slug()]) OR isset($filter_data['min_price'])) AND count($filter_data) > 1) {unset($filter_data['paged']);$_GET = $filter_data;$_REQUEST['perpage'] = -1; //for getting all products ids in WOOF predict filtrationif (isset($filter_data['post_title']) AND!empty($filter_data['post_title'])) {woot()->filter->provider($filter_data);}$WOOF->woof_products_ids_prediction(true);$ids = $_REQUEST['woof_wp_query_ids'];if ($ids) {$args['post__in'] = $ids;} else {unset($args['post__in']);}}return $args;}, 10, 2);}}}}return $profile;}, 10, 3);
- After this WOOT will be listening query arguments from WOOF
As you can see main thing there is define array $args fields in the right way.
Also the hook can be used for creating shortcodes with preselected products, lets look on the code for shortcode [woot_upsells]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | final class WOOT_WooCommerceUpsells extends WOOT_WooCommerceUniversal { public $slug = 'upsells'; public function __construct() { $this->settings_columns_title = esc_html__('Upsells columns', 'woot-products-tables'); parent::__construct(); } public function filter_provider($args, $filter_data) { if (is_array($filter_data) AND isset($filter_data['product_id']) AND intval($filter_data['product_id']) > 0) { $product = WOOT_WooCommerce::get_product(intval($filter_data['product_id'])); if ($product AND method_exists($product, 'get_upsell_ids')) { if (!$args['post__in'] = $product->get_upsell_ids()) { $args['post__in'] = [-1]; } } else { $args['post__in'] = [-1]; } } return $args; } } new WOOT_WooCommerceUpsells(); |
The hook is added into the the class WOOT_WooCommerceUniversal:
