WooCommerce archive for sale Products does not have the have all capabilities












0














I'm building an e-commerce site based on WooCommerce and use Timber (Twig) for templating. I'm now trying to build a page (e.g. domain.com/sale) which lists all my Products, that are on sale. Since I totally customized the entire WooCommerce template structure (because I'm templating in Twig), shortcodes are not an option.



My Problem:

I managed to build a custom query showing my products on sale, but it seems I'm missing something, since no pagination is shown in the bottom, neither my AJAX Filters are working.. and so on.. Probably because I'm not calling the default query? Even if I go the non-AJAX-way: domain.com/sale/page/2 it will return me the same results I already get on the first page. literally not changing anything...



What I did:

I created a page in my Wordpress named "Sale". Went to my index.php and added the following code:



<!-- index.php -->

$products = Timber::get_posts(
array(
'post_type' => 'product',
'nopaging' => false,
'posts_per_archive_page' => '24',
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
),
array( // Variable products type
'key' => '_min_variation_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
)
)
)
);

$context['products'] = $products;

Timber::render( '/pages/landingpages/sale.twig', $context );


In my option this totally works fine. And of corse this is surrounded with correct if clauses to call when domain.com/sale is requested. I now went to my sale.twig file and added following code:



sale.twig



$context = Timber::get_context();

{% block content %}
<div id="product_list" class="product_listing grid">

{{ fn('woocommerce_breadcrumb', breadcrumb_settings) }}
<h1>Sale</h1>

<div id="product_list" class="product_listing grid">

{# Filters #}
<div class="product_filter">
{{ fn('do_shortcode', '[br_filters_group group_id=7861]') }}
</div>

{# Order by #}
<div class="product_sorting">
<label for="orderby">Order by:</label>
{{ fn('woocommerce_catalog_ordering') }}
</div>

{# Products #}
<div class="product_listing-content">
<ul class="product_results products">
{% for product in products %}
{% include ('partials/loop-product.twig') %}
{% endfor %}
</ul>
<div class="products-footer">
{% include 'partials/pagination.twig' %}
</div>
</div>

</div>
</div>
{% endblock content %}


At this point I must say that I'm using BeRocket AJAX Filters for my Filters. The included files loop-product.twig and pagination.twig look like this:



loop-product.twig // deleted some lines for simplicity



<li id="{{ 'product-' ~ product._sku }}" class="product-item {{ product._stock_status }}">
{{ product.name }}
</li>


pagination.twig



<ul class="pagination clearfix">
{% if posts.pagination.prev %}
<li class="prev-item">
<a href="{{posts.pagination.prev.link}}" class="prev {{posts.pagination.prev.link|length ? '' : 'invisible'}}">
<span class="sr-only">Prev</span>
</a>
</li>
{% endif %}
{% for page in posts.pagination.pages %}
<li class="page">
{% if page.link %}
<a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
{% else %}
<span class="{{page.class}}">{{page.title}}</span>
{% endif %}
</li>
{% endfor %}
{% if posts.pagination.next %}
<li class="next-item">
<a href="{{posts.pagination.next.link}}" class="next {{posts.pagination.next.link|length ? '' : 'invisible'}}">
<span class="sr-only">Next</span>
</a>
</li>
{% endif %}
</ul>


Again to not get me wrong: I'm receiving all my products in a correct way. My problem is that it is not behaving like an archive page. Pagination, Filters etc.



Maybe there is total different approach to this topic, but it seems it is the only one. I found tuns of code snippets online with similar problems, but non of them suited for me...



Any help appreciated!





Edit:

For testing only I tried to add the common WooCommerce shortcode [sale_products] and at-least my filters work again. My Pagination still does not appear...










share|improve this question





























    0














    I'm building an e-commerce site based on WooCommerce and use Timber (Twig) for templating. I'm now trying to build a page (e.g. domain.com/sale) which lists all my Products, that are on sale. Since I totally customized the entire WooCommerce template structure (because I'm templating in Twig), shortcodes are not an option.



    My Problem:

    I managed to build a custom query showing my products on sale, but it seems I'm missing something, since no pagination is shown in the bottom, neither my AJAX Filters are working.. and so on.. Probably because I'm not calling the default query? Even if I go the non-AJAX-way: domain.com/sale/page/2 it will return me the same results I already get on the first page. literally not changing anything...



    What I did:

    I created a page in my Wordpress named "Sale". Went to my index.php and added the following code:



    <!-- index.php -->

    $products = Timber::get_posts(
    array(
    'post_type' => 'product',
    'nopaging' => false,
    'posts_per_archive_page' => '24',
    'meta_query' => array(
    'relation' => 'OR',
    array( // Simple products type
    'key' => '_sale_price',
    'value' => 0,
    'compare' => '>',
    'type' => 'numeric'
    ),
    array( // Variable products type
    'key' => '_min_variation_sale_price',
    'value' => 0,
    'compare' => '>',
    'type' => 'numeric'
    )
    )
    )
    );

    $context['products'] = $products;

    Timber::render( '/pages/landingpages/sale.twig', $context );


    In my option this totally works fine. And of corse this is surrounded with correct if clauses to call when domain.com/sale is requested. I now went to my sale.twig file and added following code:



    sale.twig



    $context = Timber::get_context();

    {% block content %}
    <div id="product_list" class="product_listing grid">

    {{ fn('woocommerce_breadcrumb', breadcrumb_settings) }}
    <h1>Sale</h1>

    <div id="product_list" class="product_listing grid">

    {# Filters #}
    <div class="product_filter">
    {{ fn('do_shortcode', '[br_filters_group group_id=7861]') }}
    </div>

    {# Order by #}
    <div class="product_sorting">
    <label for="orderby">Order by:</label>
    {{ fn('woocommerce_catalog_ordering') }}
    </div>

    {# Products #}
    <div class="product_listing-content">
    <ul class="product_results products">
    {% for product in products %}
    {% include ('partials/loop-product.twig') %}
    {% endfor %}
    </ul>
    <div class="products-footer">
    {% include 'partials/pagination.twig' %}
    </div>
    </div>

    </div>
    </div>
    {% endblock content %}


    At this point I must say that I'm using BeRocket AJAX Filters for my Filters. The included files loop-product.twig and pagination.twig look like this:



    loop-product.twig // deleted some lines for simplicity



    <li id="{{ 'product-' ~ product._sku }}" class="product-item {{ product._stock_status }}">
    {{ product.name }}
    </li>


    pagination.twig



    <ul class="pagination clearfix">
    {% if posts.pagination.prev %}
    <li class="prev-item">
    <a href="{{posts.pagination.prev.link}}" class="prev {{posts.pagination.prev.link|length ? '' : 'invisible'}}">
    <span class="sr-only">Prev</span>
    </a>
    </li>
    {% endif %}
    {% for page in posts.pagination.pages %}
    <li class="page">
    {% if page.link %}
    <a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
    {% else %}
    <span class="{{page.class}}">{{page.title}}</span>
    {% endif %}
    </li>
    {% endfor %}
    {% if posts.pagination.next %}
    <li class="next-item">
    <a href="{{posts.pagination.next.link}}" class="next {{posts.pagination.next.link|length ? '' : 'invisible'}}">
    <span class="sr-only">Next</span>
    </a>
    </li>
    {% endif %}
    </ul>


    Again to not get me wrong: I'm receiving all my products in a correct way. My problem is that it is not behaving like an archive page. Pagination, Filters etc.



    Maybe there is total different approach to this topic, but it seems it is the only one. I found tuns of code snippets online with similar problems, but non of them suited for me...



    Any help appreciated!





    Edit:

    For testing only I tried to add the common WooCommerce shortcode [sale_products] and at-least my filters work again. My Pagination still does not appear...










    share|improve this question



























      0












      0








      0


      0





      I'm building an e-commerce site based on WooCommerce and use Timber (Twig) for templating. I'm now trying to build a page (e.g. domain.com/sale) which lists all my Products, that are on sale. Since I totally customized the entire WooCommerce template structure (because I'm templating in Twig), shortcodes are not an option.



      My Problem:

      I managed to build a custom query showing my products on sale, but it seems I'm missing something, since no pagination is shown in the bottom, neither my AJAX Filters are working.. and so on.. Probably because I'm not calling the default query? Even if I go the non-AJAX-way: domain.com/sale/page/2 it will return me the same results I already get on the first page. literally not changing anything...



      What I did:

      I created a page in my Wordpress named "Sale". Went to my index.php and added the following code:



      <!-- index.php -->

      $products = Timber::get_posts(
      array(
      'post_type' => 'product',
      'nopaging' => false,
      'posts_per_archive_page' => '24',
      'meta_query' => array(
      'relation' => 'OR',
      array( // Simple products type
      'key' => '_sale_price',
      'value' => 0,
      'compare' => '>',
      'type' => 'numeric'
      ),
      array( // Variable products type
      'key' => '_min_variation_sale_price',
      'value' => 0,
      'compare' => '>',
      'type' => 'numeric'
      )
      )
      )
      );

      $context['products'] = $products;

      Timber::render( '/pages/landingpages/sale.twig', $context );


      In my option this totally works fine. And of corse this is surrounded with correct if clauses to call when domain.com/sale is requested. I now went to my sale.twig file and added following code:



      sale.twig



      $context = Timber::get_context();

      {% block content %}
      <div id="product_list" class="product_listing grid">

      {{ fn('woocommerce_breadcrumb', breadcrumb_settings) }}
      <h1>Sale</h1>

      <div id="product_list" class="product_listing grid">

      {# Filters #}
      <div class="product_filter">
      {{ fn('do_shortcode', '[br_filters_group group_id=7861]') }}
      </div>

      {# Order by #}
      <div class="product_sorting">
      <label for="orderby">Order by:</label>
      {{ fn('woocommerce_catalog_ordering') }}
      </div>

      {# Products #}
      <div class="product_listing-content">
      <ul class="product_results products">
      {% for product in products %}
      {% include ('partials/loop-product.twig') %}
      {% endfor %}
      </ul>
      <div class="products-footer">
      {% include 'partials/pagination.twig' %}
      </div>
      </div>

      </div>
      </div>
      {% endblock content %}


      At this point I must say that I'm using BeRocket AJAX Filters for my Filters. The included files loop-product.twig and pagination.twig look like this:



      loop-product.twig // deleted some lines for simplicity



      <li id="{{ 'product-' ~ product._sku }}" class="product-item {{ product._stock_status }}">
      {{ product.name }}
      </li>


      pagination.twig



      <ul class="pagination clearfix">
      {% if posts.pagination.prev %}
      <li class="prev-item">
      <a href="{{posts.pagination.prev.link}}" class="prev {{posts.pagination.prev.link|length ? '' : 'invisible'}}">
      <span class="sr-only">Prev</span>
      </a>
      </li>
      {% endif %}
      {% for page in posts.pagination.pages %}
      <li class="page">
      {% if page.link %}
      <a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
      {% else %}
      <span class="{{page.class}}">{{page.title}}</span>
      {% endif %}
      </li>
      {% endfor %}
      {% if posts.pagination.next %}
      <li class="next-item">
      <a href="{{posts.pagination.next.link}}" class="next {{posts.pagination.next.link|length ? '' : 'invisible'}}">
      <span class="sr-only">Next</span>
      </a>
      </li>
      {% endif %}
      </ul>


      Again to not get me wrong: I'm receiving all my products in a correct way. My problem is that it is not behaving like an archive page. Pagination, Filters etc.



      Maybe there is total different approach to this topic, but it seems it is the only one. I found tuns of code snippets online with similar problems, but non of them suited for me...



      Any help appreciated!





      Edit:

      For testing only I tried to add the common WooCommerce shortcode [sale_products] and at-least my filters work again. My Pagination still does not appear...










      share|improve this question















      I'm building an e-commerce site based on WooCommerce and use Timber (Twig) for templating. I'm now trying to build a page (e.g. domain.com/sale) which lists all my Products, that are on sale. Since I totally customized the entire WooCommerce template structure (because I'm templating in Twig), shortcodes are not an option.



      My Problem:

      I managed to build a custom query showing my products on sale, but it seems I'm missing something, since no pagination is shown in the bottom, neither my AJAX Filters are working.. and so on.. Probably because I'm not calling the default query? Even if I go the non-AJAX-way: domain.com/sale/page/2 it will return me the same results I already get on the first page. literally not changing anything...



      What I did:

      I created a page in my Wordpress named "Sale". Went to my index.php and added the following code:



      <!-- index.php -->

      $products = Timber::get_posts(
      array(
      'post_type' => 'product',
      'nopaging' => false,
      'posts_per_archive_page' => '24',
      'meta_query' => array(
      'relation' => 'OR',
      array( // Simple products type
      'key' => '_sale_price',
      'value' => 0,
      'compare' => '>',
      'type' => 'numeric'
      ),
      array( // Variable products type
      'key' => '_min_variation_sale_price',
      'value' => 0,
      'compare' => '>',
      'type' => 'numeric'
      )
      )
      )
      );

      $context['products'] = $products;

      Timber::render( '/pages/landingpages/sale.twig', $context );


      In my option this totally works fine. And of corse this is surrounded with correct if clauses to call when domain.com/sale is requested. I now went to my sale.twig file and added following code:



      sale.twig



      $context = Timber::get_context();

      {% block content %}
      <div id="product_list" class="product_listing grid">

      {{ fn('woocommerce_breadcrumb', breadcrumb_settings) }}
      <h1>Sale</h1>

      <div id="product_list" class="product_listing grid">

      {# Filters #}
      <div class="product_filter">
      {{ fn('do_shortcode', '[br_filters_group group_id=7861]') }}
      </div>

      {# Order by #}
      <div class="product_sorting">
      <label for="orderby">Order by:</label>
      {{ fn('woocommerce_catalog_ordering') }}
      </div>

      {# Products #}
      <div class="product_listing-content">
      <ul class="product_results products">
      {% for product in products %}
      {% include ('partials/loop-product.twig') %}
      {% endfor %}
      </ul>
      <div class="products-footer">
      {% include 'partials/pagination.twig' %}
      </div>
      </div>

      </div>
      </div>
      {% endblock content %}


      At this point I must say that I'm using BeRocket AJAX Filters for my Filters. The included files loop-product.twig and pagination.twig look like this:



      loop-product.twig // deleted some lines for simplicity



      <li id="{{ 'product-' ~ product._sku }}" class="product-item {{ product._stock_status }}">
      {{ product.name }}
      </li>


      pagination.twig



      <ul class="pagination clearfix">
      {% if posts.pagination.prev %}
      <li class="prev-item">
      <a href="{{posts.pagination.prev.link}}" class="prev {{posts.pagination.prev.link|length ? '' : 'invisible'}}">
      <span class="sr-only">Prev</span>
      </a>
      </li>
      {% endif %}
      {% for page in posts.pagination.pages %}
      <li class="page">
      {% if page.link %}
      <a href="{{page.link}}" class="{{page.class}}">{{page.title}}</a>
      {% else %}
      <span class="{{page.class}}">{{page.title}}</span>
      {% endif %}
      </li>
      {% endfor %}
      {% if posts.pagination.next %}
      <li class="next-item">
      <a href="{{posts.pagination.next.link}}" class="next {{posts.pagination.next.link|length ? '' : 'invisible'}}">
      <span class="sr-only">Next</span>
      </a>
      </li>
      {% endif %}
      </ul>


      Again to not get me wrong: I'm receiving all my products in a correct way. My problem is that it is not behaving like an archive page. Pagination, Filters etc.



      Maybe there is total different approach to this topic, but it seems it is the only one. I found tuns of code snippets online with similar problems, but non of them suited for me...



      Any help appreciated!





      Edit:

      For testing only I tried to add the common WooCommerce shortcode [sale_products] and at-least my filters work again. My Pagination still does not appear...







      php wordpress woocommerce twig






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 23:32

























      asked Nov 20 at 23:21









      Antoine Henrich

      6319




      6319
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I am going to take a stab at helping. Please forgive me if I am off base. The gutenburg blocks is still very hard for me to grasp.



          Your sale.twig is dynamically pulling data and using JS to fill content via a php include but it never actually writes the content via the WP hooks to the database that the /sale page or post is pulling the data from. Is that intentional?



          Also note the twig js that is supposed to provide you the pagenation from the dom does not match the dom created via link_template.php
          have a look



          I kind of think you will have to call this



          <?php previous_post_link( '<strong>%link</strong>' ); ?> 


          link_template






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403097%2fwoocommerce-archive-for-sale-products-does-not-have-the-have-all-capabilities%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I am going to take a stab at helping. Please forgive me if I am off base. The gutenburg blocks is still very hard for me to grasp.



            Your sale.twig is dynamically pulling data and using JS to fill content via a php include but it never actually writes the content via the WP hooks to the database that the /sale page or post is pulling the data from. Is that intentional?



            Also note the twig js that is supposed to provide you the pagenation from the dom does not match the dom created via link_template.php
            have a look



            I kind of think you will have to call this



            <?php previous_post_link( '<strong>%link</strong>' ); ?> 


            link_template






            share|improve this answer




























              0














              I am going to take a stab at helping. Please forgive me if I am off base. The gutenburg blocks is still very hard for me to grasp.



              Your sale.twig is dynamically pulling data and using JS to fill content via a php include but it never actually writes the content via the WP hooks to the database that the /sale page or post is pulling the data from. Is that intentional?



              Also note the twig js that is supposed to provide you the pagenation from the dom does not match the dom created via link_template.php
              have a look



              I kind of think you will have to call this



              <?php previous_post_link( '<strong>%link</strong>' ); ?> 


              link_template






              share|improve this answer


























                0












                0








                0






                I am going to take a stab at helping. Please forgive me if I am off base. The gutenburg blocks is still very hard for me to grasp.



                Your sale.twig is dynamically pulling data and using JS to fill content via a php include but it never actually writes the content via the WP hooks to the database that the /sale page or post is pulling the data from. Is that intentional?



                Also note the twig js that is supposed to provide you the pagenation from the dom does not match the dom created via link_template.php
                have a look



                I kind of think you will have to call this



                <?php previous_post_link( '<strong>%link</strong>' ); ?> 


                link_template






                share|improve this answer














                I am going to take a stab at helping. Please forgive me if I am off base. The gutenburg blocks is still very hard for me to grasp.



                Your sale.twig is dynamically pulling data and using JS to fill content via a php include but it never actually writes the content via the WP hooks to the database that the /sale page or post is pulling the data from. Is that intentional?



                Also note the twig js that is supposed to provide you the pagenation from the dom does not match the dom created via link_template.php
                have a look



                I kind of think you will have to call this



                <?php previous_post_link( '<strong>%link</strong>' ); ?> 


                link_template







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 at 3:47

























                answered Nov 21 at 3:36









                Jeremiah Stillings

                4781315




                4781315






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403097%2fwoocommerce-archive-for-sale-products-does-not-have-the-have-all-capabilities%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen