Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

php - Product Category Filter with AJAX AND Image Buttons on Divi / Woocommerce

I want to create an AJAX product category filter that loads instantly, in the same page, like the one below:

Ajax "instant" filter:
image 1 - ajax "instant" filter

The only difference is that instead of a little box with text, I want to have an image as the button.

Using clickable images as categories selectors:
image 2 - using clickable images as categories selectors

Is that possible?

I’m using Divi Theme Builder and WooCommerce.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are multiple approach to resolve above problem.

Bind click event to image : <img src="./thumb.png" onclick="filterProduct('cat1');" width="200" height="200" />

  1. If your store going have limited products, then query all and the filter using JavaScript, bind click event to the image and let JavaScript filter from array.

  2. Bind click event to the image, then make ajax call, see WP Ajax. In that ajax call write query to get category specific product like :

    $prods = wc_get_products( array('category' => array('category-slug')) );

I would recommend second approach.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...