mercredi 30 mars 2016

Force execute Woocommerce main query with pre_get_post

I'm trying to build an widget with filters the main woocommerce query to display specific products. I'm looking for a way of updating the query and re executing with no luck . The query from the archive-product.php

<?php if ( have_posts() ) : do_action( 'woocommerce_before_shop_loop' ); ?><?php endif; ?>
<?php do_action( 'woocommerce_archive_description' ); ?>

    <?php if ( have_posts() ) : ?>

        <?php woocommerce_product_loop_start(); ?>
            <?php woocommerce_product_subcategories(); ?>

            <?php while ( have_posts() ) : the_post(); ?>
                <?php woocommerce_get_template_part( 'content', 'product' ); ?>
            <?php endwhile; // end of the loop. ?>

        <?php woocommerce_product_loop_end(); ?>

        <?php
            /**
             * woocommerce_after_shop_loop hook
             *
             * @hooked woocommerce_pagination - 10
             */
            do_action( 'woocommerce_after_shop_loop' );
        ?>

I want to add a hook like

 add_action( 'woocommerce_product_query', 'so_27971630_product_query' );

function so_27971630_product_query( $q ){
    $meta_query = $q->get( 'meta_query' );
    $meta_query[] = array(
        'key' => 'custom_acf_key',
        'value' => 'custom_acf_value',
        'compare' => '='
        );

    $q->set( 'meta_query', $meta_query );
}

and re execute the query displaying the results in a div with ajax. I've done the ajax part and i'm stuck in the way of re executing the query



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire