• I have 1 product “service” I sell, but the ID, price, and description is always different for every sale. Now there is no way I can have a product with every possible variation. Now I have written a script that will get the ID number, Description, and the price and put them into strings. I need to find if there is a way to add a Add To Cart button to a page that will pass this into the cart without having to use the product page.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Don’t know if these will work for you, but you could try calling the cart page with the querystring:
    ?add-to-cart=3111 where 3111 is the id of you product.

    Or make an Add to Cart shortcode:
    https://docs.woocommerce.com/document/woocommerce-shortcodes/
    implemented using do_shortcode() if necessary.

    Thread Starter crwhite57

    (@crwhite57)

    Thanks but that would call the information in the product page including the price. I need to be able to change the price that is sent to the cart.

    If you have an infinite number of unique products, I understood that you were making them dynamically. So you would create a product object:
    $my_product = new WC_Product_Simple;
    then set the price, say £20:
    $my_product->set_price(20);
    next, get the id:
    $product_id = $my_product->the_id();
    Its this id that is passed to the cart.

    See:
    https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html

    Thread Starter crwhite57

    (@crwhite57)

    OK what it is I run a DJ service with 4 basic services, Dj Service, DJ/Karaoke Service, Corporate DJ, and Corporate DJ/Karaoke Service. What I was thinking is I have 4 products so I have 4 product IDs. Now what I want to do is if possible is have a button that would use a url that uses the product ID but pass a new price to the cart without it having to create a new product otherwise it would create thousands of products.

    Maybe something like:

    
    $product_id = (from your script)
    // fetch the product object
    $my_product = wc_get_product($product_id);
    // reset the price
    $my_product->set_price(20);
    $url = 'http:/www.mysite.com/cart/?add-to-cart='.$product_id;
    
    Thread Starter crwhite57

    (@crwhite57)

    Ok here is what I have:
    $product_id = (1400);
    // fetch the product object
    $my_product = wc_get_product($product_id);
    // reset the price
    $my_product->set_price(20);
    $url = ‘www.pegasussal.com/?add-to-cart=’.$product_id;
    ?>
    <form action=”<?php echo $url; ?>” method=”post” target=”_top”>
    <input type=”submit” value=”Pay Now”>
    </form>
    Now it works great except it adds the price in the product page, not the new price. Just so you know the product name I am testing this on is “DJ Service”.

    I found the product page but not the “Pay Now” button. How does the customer input the number of hours and add-ons required – this information is of course needed by your script to calculate the price.

    This looks to me like a variable product with add-ons application. I understand that your variable product can’t have a variation for every possible combination of add-on, that would be too many. So the variations are just the number of hours required. Presumably these are integers, so maximum say 6 hours. Below that would be a checkbox list of required add-ons.

    Booster (free version)
    https://wordpress.org/plugins/woocommerce-jetpack/
    Has a product add-ons module. This can work either by product or, better for you, globally for each product. This can be setup to produce a list of labelled checkboxes beneath the variation dropdown. There would be one checkbox for each add-on. Booster calculates the price and the item in the cart includes a list of the add-ons selected.

    There are also premium add-on plugins you can look at:
    http://codecanyon.net/item/woocommerce-extra-product-options/7908619
    http://codecanyon.net/item/product-options-for-woocommerce-wp-plugin/7973927
    http://www.woothemes.com/products/product-add-ons/

    None of this is tied to availability, so I don’t know how you would stop someone buying service on a day you were busy. For this, you would need a quote system.
    https://codecanyon.net/item/woocommerce-request-a-quote/6460218
    and others.
    The way this works is that the user puts together a “shopping list” of the things they want with a note of the day, any special requests and their contact details. They can then click a button to email you with this list.

    Thread Starter crwhite57

    (@crwhite57)

    I use MDJM Event Manger and here is how it works. Say you are the client, you fill out the quote request with any add-ons you may want. I get an email with all of the details and put it into the system. You then get an email with the quote and a link to see a detailed quote. You desside to go ahead with the price quoted to you where you then click Book Event and sign the contract. At that point the event date is blocked out from anyone else trying to book it and (this is the part I am trying to get done) you would then add to cart the deposit or the full cost in the “Manage Your Event screen”.

    I have the script written to get all the information like Event ID, Type of service, the deposit amount, the total amount, and the balance if a deposit is made. The button only appears once you have signed the contract and if you have not made your deposit or a balance is yet outstanding. Like I said, if I type everything to manually put it into the cart, it works with the item in the product page, but if I try to do it with what I put in last time, it only sends “www.pegasussal.com/?” and not the rest of it.
    I don’t know if it is something in the submit button of what.

    • This reply was modified 7 years, 8 months ago by crwhite57.
    • This reply was modified 7 years, 8 months ago by crwhite57.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom Add to cart Button’ is closed to new replies.