WOOT - Таблицы активных продуктов WooCommerce

woot_filter_provider_

Эти хуки позволяют сделать совместимые плагины фильтров woocommerce с WOOT.

Рассмотрим адаптацию фильтра для гав (В качестве примера):

  • в файл functions.php текущей темы wordpress добавьте следующий код:
    add_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);} если (! empty ($ filter_data) AND is_array ($ filter_data)) {foreach (array_keys ($ filter_data) as $ key) {if (is_integer ($ key)) {unset ($ filter_data [$ key]);}}} / / *** // здесь чистая глобальная функциональность WOOF $ 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; // для получения всех идентификаторов товаров в WOOF прогнозируйте fi фильтрация if (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']; если ($ ids) {$ args ['post__in'] = $ ids; } else {unset ($ args ['post__in']); }} return $ args; }, 10, 2); }}}} вернуть $ profile; }, 10, 3);
    
  • После этого WOOT будет прослушивать аргументы запроса от WOOF

Как видите, главное - правильно определить поля массива $ args.


Также крючок можно использовать для создания шорткодов с заранее выбранными товарами, давайте посмотрим код шорткода [woot_upsells]:

последний класс WOOT_WooCommerceUpsells расширяет WOOT_WooCommerceUniversal {public $ slug = 'upsells'; публичная функция __construct () {$ this-> settings_columns_title = esc_html __ ('Дополнительные столбцы', 'woot-products-tables'); родитель :: __ construct (); } общедоступная функция 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]; }} еще {$ args ['post__in'] = [-1]; }} return $ args; }} новый WOOT_WooCommerceUpsells ();

Хук добавлен в класс WOOT_WooCommerceUniversal: