Custom add to cart code from a few years ago needs adjusting

Home Forums Bug reporting, Questions & Suggestions Ajax Search Pro for WordPress Custom add to cart code from a few years ago needs adjusting

This topic contains 0 replies, has 1 voice, and was last updated by Planetdune Planetdune 4 years, 3 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #17513
    Planetdune
    Planetdune
    Participant

    Hello

    I got a custom function that I have been using for years that instead of opening the individual product pages on result click it adds the product to the cart. I do not use individual product pages at all so this was perfect.

    However, I am now using the “Woocommerce Cart” plugin (https://wordpress.org/plugins/side-cart-woocommerce/) and things are going wrong. instead of adding things to cart I get this (see image below). As you can see it adds it, then says it is already added.. and it doesn’t open the cart (or even better, add it to the side cart using the new plugin).. I could even be okay if it just added it to cart and open the cart page as it did previously..

    Here is the code:

    add_filter( ‘asp_results’, ‘asp_links_to_addtocart’, 1, 1 );

    function asp_links_to_addtocart( $results ) {
    foreach ($results as $k=>$r) {
    $lang_arg = “”;
    if ( isset($_POST[“options”]) ) {
    $opt = wp_parse_args($_POST[“options”], array());
    $lang_arg = “&lang=” . $opt[“wpml_lang”];
    }
    // Modify the URL
    $results[$k]->link = ‘/?add-to-cart=’.$r->id.’&quantity=1′.$lang_arg;
    }
    return $results;
    }

    Thank you!

    Attachments:
    You must be logged in to view attached files.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.