Dropdown menu on custom page with product to choose number of products per page

Home Forums SKT Full Width Forum Dropdown menu on custom page with product to choose number of products per page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #192417
    Maria BordoliMaria Bordoli
    Participant
    • Topics: 46
    • Replies: 58
    • Total: 104
    Member since: December 14, 2021

    Good morning,
    I have the e-shop “aeliaspa.gr”. Most likely what I will ask is not about your piece, but because I could not find the solution elsewhere I thought to ask you too. If you want to help me on the follow.
    The pages of the store are custom page. I use shortcode, for example the home page is shortcode: [products columns = "4" limit = "100" paginate = "true"].
    I try to add a dropdown textbox through which the customer can choose how many products he will see on each page, ie if he wants to see 20, 50, 100 or all. I have tried plug in others because it is custom the page does not work. I have find a code but it does not work. It would be easy to help me. If not I fully understand. Follow the code:

    add_action( ‘woocommerce_before_shop_loop’, ‘ps_selectbox’, 25 );
    function ps_selectbox() {
    $per_page = filter_input(INPUT_GET, ‘$per_page’, FILTER_SANITIZE_NUMBER_INT);
    echo ‘<span>Per Page: </span>’;
    echo ‘<select onchange=”if (this.value) window.location.href=this.value”>’;
    $orderby_options = array( ‘8’ => ‘8’, ’16’ => ’16’,’32’ => ’32’,’64’ => ’64’ );
    foreach( $orderby_options as $value => $label ) {
    echo “<option “.selected( $per_page, $value ).” value=’?$per_page=$value’>$label</option>”;
    }
    echo ‘</select>’;
    }
    add_action( ‘pre_get_posts’, ‘ps_pre_get_products_query’ );
    function ps_pre_get_products_query( $query ) {
    $per_page = filter_input(INPUT_GET, ‘$per_page’, FILTER_SANITIZE_NUMBER_INT);

    if ( ! is_admin() && is_woocommerce() && is_page() ) {
    $query->set( ‘posts_per_page’, $per_page );
    }
    }

    function render_ps_sel() {
    return ps_selectbox();
    }
    add_shortcode( ‘ps_selectbox’, ‘render_ps_sel’ );

    Thanks and sorry for the inconvenience.

    #192436
    Sonl SinhaSonl Sinha
    Moderator
    • Topics: 0
    • Replies: 31029
    • Total: 31029
    Member since: August 16, 2013

    Hi,

    Kindly use this plugin to number of products.
    https://wordpress.org/plugins/load-more-products-for-woocommerce/

    Hope this help you.

    Regards,
    Dave

    #192437
    Maria BordoliMaria Bordoli
    Participant
    • Topics: 46
    • Replies: 58
    • Total: 104
    Member since: December 14, 2021

    Thanks very much! I Will try:)

    #192438
    Sonl SinhaSonl Sinha
    Moderator
    • Topics: 0
    • Replies: 31029
    • Total: 31029
    Member since: August 16, 2013

    Okay

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.