WOOT - WooCommerce Active Products-tabellen

woot_filter_provider_

Deze hooks maken het mogelijk om compatibele woocommerce-filters plug-ins te maken met WOOT.

Laten we de filteraanpassing bekijken voor INSLAG (als voorbeeld):

  • in het bestand functions.php van het huidige wordpress-thema de volgende code toevoegen:
    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); } if (!empty($filter_data) AND is_array($filter_data)) { foreach (array_keys($filter_data) as $key) { if (is_integer($key)) { unset($filter_data[$key]); } } } / /*** //hier is schone WOOF-functionaliteit global $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; // voor het verkrijgen van alle product-ID's in WOOF voorspellen fi ltratie 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']; if ($ids) { $args['post__in'] = $ids; } else { unset($args['post__in']); } } retourneer $args; }, 10, 2); } } } } retourneer $profiel; }, 10, 3);
    
  • Hierna luistert WOOT naar vraagargumenten van WOOF

Zoals u kunt zien, is het belangrijkste dat u array $ args-velden op de juiste manier definieert.


De haak kan ook worden gebruikt voor het maken van shortcodes met vooraf geselecteerde producten, laten we kijken naar de code voor shortcode [woot_upsells]:

laatste klasse WOOT_WooCommerceUpsells breidt WOOT_WooCommerceUniversal uit { public $slug = 'upsells'; openbare functie __construct() { $this->settings_columns_title = esc_html__('Upsells kolommen', 'woot-products-tables'); ouder::__construct(); } openbare functie 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]; } } retourneer $args; } } nieuwe WOOT_WooCommerceUpsells();

De haak wordt aan de klas toegevoegd WOOT_WooCommerceUniversal: