• Resolved Justin

    (@azyrus_pok)


    Hey ILLID, hey everyone.

    How good would a add to cart button be in the AJAX search result? Have you done this or could you point me in the right direction to build this?

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Justin

    (@azyrus_pok)

    Hey ILLID,

    I’m hoping to add:

    
    if ( ( typeof response.cats !== 'undefined' ) && response.cats.length > 0 ) {
    
                        $.each(response.cats, function (i, result) {
    
                            html += '<li class="aws_result_item aws_result_cat">';
                            html += '<a class="aws_result_link" href="' + result.link + '" >';
                            html += '<span class="aws_result_content">';
                            html += '<span class="aws_result_title">';
                            html += result.name;
                            html += '<span class="aws_result_count"> (' + result.count + ')</span>';
                            html += '</span>';
                            html += '</span>';
    						html += '<a href="https://www.website.com/cart/?add-to-cart= (' + result.id + ')">Add To Cart</a>'
                            html += '</a>';
                            html += '</li>';
    
                        });
    
                    }
    

    How do you propose I pull the $post_ID into the common.js result.id variable?

    Thanks!

    Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Find loop

    $.each(response.products, function (i, result) {
    .............
    }

    and inside it you can call

    result.post_data.ID

    to get product ID.

    • This reply was modified 6 years, 6 months ago by ILLID.

    Did this work? do you have a demo?

    Thread Starter Justin

    (@azyrus_pok)

    Hey Wayne,

    if result on sale starts at line 176. (advanced woo search > assets > common.js)

    
                            if ( result.on_sale ) {
                                html += '<span class="aws_result_sale">';
                                html += '<span class="aws_onsale">' + translate.sale + '</span>';
                                html += '</span>';
                            }
    
                            html += '</a>';
    						html += '<a href="https://www.website.com/cart/?add-to-cart= (' + result.post_data.ID + ')" style="float:right;">Add To Cart</a>'
                            html += '</li>';
    

    That did work, unfortunately I can’t provide a demo.

    Good luck!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add To Cart Button’ is closed to new replies.