[ajax-list] Plugin (2024-11-29 – Add to card bugs)

Update the plugin and clear the cache.

2.Create two files in your bravada-plus-child folder (woocommerce.php and search.php) and paste the code below into them. If these files already exist, simply edit them.

search.php
<?php
// search.php
get_header(); ?>


   <div id="container" class="<?php bravada_get_layout_class(); ?>">

       <main id="main" class="main">

           <?php cryout_before_content_hook(); ?>


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


               <header class="page-header content-search pad-container" <?php cryout_schema_microdata( 'element' );
?>>

                   <h1 class="page-title" <?php cryout_schema_microdata( 'entry-title' );
?>>

                       <?php printf( __( 'Search Results for: %s', 'bravada' ), '<strong>' . get_search_query() . '</strong>' );
?>

                   </h1><br>

                   <?php get_search_form(); ?>

               </header>


               <div id="content-masonry" class="content-masonry" <?php cryout_schema_microdata( 'element' );
?>>

                   <?php /* Start the Loop */

  /*                 while ( have_posts() ) : the_post();

                       get_template_part( 'search/content', '' );

                   endwhile;
   */
                   ?>

               </div><!--content-masonry-->

               <?php


//               bravada_pagination();
echo do_shortcode('[ajax-list  sort="default" ]');

           else :


               get_template_part( 'content/content', 'notfound' );

               ?> <div id="content-masonry"></div> <?php


               cryout_empty_page_hook();


           endif; ?>


           <?php cryout_after_content_hook(); ?>

       </main><!-- #main -->


       <?php bravada_get_sidebar(); ?>

   </div><!-- #primary -->


<?php get_footer(); ?>
woocommerce.php
<?php
//woocommerce.php
get_header(); ?>

	<div id="container" class="<?php bravada_get_layout_class(); ?>">

		<main id="main" class="main">

		<article id="post-<?php the_ID(); ?>" <?php post_class( 'hentry' ); ?>>
			<div class="article-inner">
				<?php cryout_before_content_hook(); ?>
				<?php
		if (is_product_category()) {
			$term = get_queried_object();
			$category_id = $term->term_id;
			echo do_shortcode('[ajax-list cats="'.$category_id.'" sort="default"  ]');
		}
		else if (is_product_tag()) {
			$term = get_queried_object();
			$tag_id = $term->term_id;
			echo do_shortcode('[ajax-list tags="'.$tag_id.'" sort="default"  ]');
		}
		else {
		?>
				<?php woocommerce_content(); ?>
		<?php } ?>

				<?php cryout_after_content_hook(); ?>
			</div><!-- .article-inner -->
		</article><!-- #post-## -->
		</main><!-- #main -->

		<?php bravada_get_sidebar(); ?>

	</div><!-- #container -->

<?php get_footer();

3.Additionally, remove lines 301–310 in functions.php, as they are no longer needed and conflict with my code.

// Remove this 👇
add_filter( 'pre_get_posts', function( $query ) {
		if ( $query->is_search && ! is_admin() ) {
				$query->set( 'post_type', 'product' );
				$query->is_post_type_archive = true;
		}
}, 9 );

Here’s a quick guide to using the [ajax-list] shortcode:

  • Attributes it accepts:
    • cats: Enter a category ID to filter products (leave empty to show all).
    • sort: Options include:
      • "" or “default” (latest added products)
      • "popularity" 
      • "rating"
      • "date"
      • "price"
      • "price-desc"
      • "alphabetical"
      • "alphabetical-desc".
    • n: Number of products to display initially.
    • p: Set to "off" to hide pagination and the “Load More” button.
  • Examples:
    • Recent products in Africa category:
      [ajax-list cats="44"]
    • Last 4 products in Africa category without pagination:
      [ajax-list cats="44" sort="default" n="4" p="off"]
    • 9 Recent Products in all categories:
      [ajax-list cats="" sort="default" n="9"] (9 products in 3 rows of 3).