0

I create a custom post type named it 'en-ads' and taxonomy 'en-ads-cat'.

I create a ajax search and it showed wanted post. each of these items has a check box that if user check it that item is added to something like woocommerce cart in another page. and when click the show cart button. user can see all selected items on that cart page. also if user wants to come back and add something new to the cart, past cart items should stored and exclude douplicate posts. also user can delete an item in cart and add new in first page.

my search page is 'site/ooh' and cart page is 'site/ooh-cart'

this is the html that I get from search result:

    <ul class="ajax_filter_search_results__list">
        <li id="ad-1230" class="ad-item">
            <img src="billboard title 1.jpg" class="ad-item__image--img">
            <div class="ad-item__info">
                <h4 class="ad-item__info--billboard">billboard title 1</h4>
                <div class="ad-item__info--list">
                    <p class="ad-item__info--item">billboard title 1 state</p>
                    <p class="ad-item__info--item">billboard title 1 city</p>
                    <p class="ad-item__info--item">billboard title 1 light : yes</p>
                    <p class="ad-item__info--item">billboard title 1 size: 10x2</p>
                    <p class="ad-item__info--item">billboard title 1 date: 2023-08-10</p>
                    <p class="ad-item__info--item">billboard title 1 price: 30000$</p>
                    <label class="ad-item__info--item ad-item__info--item-label">
                        <input type="checkbox" value="[object Object]" class="ad-item__info--add-to-pdf">
                    </label>
                </div>
            </div>
        </li>
        <li id="ad-1230" class="ad-item ad-item--add-to-cart">
            <img src="billboard title 2.jpg" class="ad-item__image--img">
            <div class="ad-item__info">
                <h4 class="ad-item__info--billboard">billboard title 2</h4>
                <div class="ad-item__info--list">
                    <p class="ad-item__info--item">billboard title 2 state</p>
                    <p class="ad-item__info--item">billboard title 2 city</p>
                    <p class="ad-item__info--item">billboard title 2 light : no</p>
                    <p class="ad-item__info--item">billboard title 2 size: 50x3</p>
                    <p class="ad-item__info--item">billboard title 2 date: 2023-09-10</p>
                    <p class="ad-item__info--item">billboard title 2 price: 40000$</p>
                    <label class="ad-item__info--item ad-item__info--item-label">
                        <input type="checkbox" value="[object Object]" class="ad-item__info--add-to-pdf">
                    </label>
                </div>
            </div>
        </li>
        <li id="ad-1230" class="ad-item ad-item--add-to-cart">
            <img src="billboard title 3.jpg" class="ad-item__image--img">
            <div class="ad-item__info">
                <h4 class="ad-item__info--billboard">billboard title 3</h4>
                <div class="ad-item__info--list">
                    <p class="ad-item__info--item">billboard title 3 state</p>
                    <p class="ad-item__info--item">billboard title 3 city</p>
                    <p class="ad-item__info--item">billboard title 3 light : yes</p>
                    <p class="ad-item__info--item">billboard title 3 size: 50x3</p>
                    <p class="ad-item__info--item">billboard title 3 date: 2023-12-10</p>
                    <p class="ad-item__info--item">billboard title 3 price: 7000$</p>
                    <label class="ad-item__info--item ad-item__info--item-label">
                        <input type="checkbox" value="[object Object]" class="ad-item__info--add-to-pdf">
                    </label>
                </div>
            </div>
        </li>
    </ul>
<a href="site/ohh-cart" class="cart-page">view cart</a>

when checkbox checked that li item get class 'ad-item--add-to-cart'. only these items must export to cart page.

how can I achieve this? Any useful help is appreciated.

Alipvd
  • 71
  • 7
  • You should probably start by wrapping this into a form, and replacing the link with a submit button. – CBroe Aug 10 '23 at 10:55
  • You could wrap it all in a `
    ` element and make the “view cart” link a `
    – Klaassiek Aug 10 '23 at 10:58
  • @Klaassiek I don't know how store selected items in database and get in cart page. would you please give full code. my only solution for this is store selected items in localstorage and get them on cart page that I don't know how too! ;) – Alipvd Aug 10 '23 at 11:07
  • That is not how it works on stackoverflow. If you need a coder to write your code, then hire one. – Klaassiek Aug 10 '23 at 12:40
  • Anyway, you can accomplish this with javascript only by indeed using localstorage. Show us the code you have and point out the problematic parts and you might get help solving the stuff that you don’t understand. – Klaassiek Aug 10 '23 at 12:42
  • @Klaassiek I know how the stack works! I just want a simple starter code to know how can I store something and use it in another page in wordpress. You were misunderstood to think so. – Alipvd Aug 11 '23 at 06:15
  • If anyone see a stack question or a basic guide that how to do this please put the link for me. thanks – Alipvd Aug 11 '23 at 07:01
  • Using localstorage has nothing to do with wordpress. Unless you mean how to include Javascript files in Wordpress. Here is how to do that: https://gloriathemes.com/wordpress-enqueue-scripts-and-styles/#:~:text=Enqueuing%20scripts%20and%20styles%20in%20the%20WordPress%20backend,-In%20addition%20to&text=First%2C%20you'll%20need%20to,style%20using%20wp_enqueue_script%20or%20wp_enqueue_style%20. – Klaassiek Aug 11 '23 at 16:18
  • Your question is too vague. How to use localstorage can be found here: https://blog.logrocket.com/localstorage-javascript-complete-guide/ – Klaassiek Aug 11 '23 at 16:19
  • How to get checkbox values using jQeury: https://stackoverflow.com/questions/2834350/get-checkbox-value-in-jquery – Klaassiek Aug 11 '23 at 16:20
  • What else do you need help with? – Klaassiek Aug 11 '23 at 16:20

0 Answers0