Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create custom 'Add to cart' with wordpress woocommerce

I fetch a specific product in a page that is outside of woocommerce template and I need to add the 'Add to cart' button. I looked at the code and I saw woocommerce doing it this way,

<a href="/?product_cat=icecream&amp;add-to-cart=77" rel="nofollow" data-product_id="77" data-product_sku="" class="button add_to_cart_button product_type_simple">Add to cart</a>

I tried to change the product_id and everything to be fit to my needs like this,

<a href="/?product_cat=icecream&amp;add-to-cart=<?php echo $id; ?>" rel="nofollow" data-product_id="<?php echo $id; ?>" data-product_sku="" class="button add_to_cart_button product_type_simple">
    <img src="<?php echo get_bloginfo('template_directory'); ?>/images/add_to_cart.png" alt="Add to cart" />
</a>

but it dosen't get saved for some reason (when I get into cart page its empty). I'm trying also to lose the "View Cart" button that gets near when the item is added, if someone can guide me how can I create that button and where to shall I redirect it, it would be perfect (:

thanks !

like image 433
greW Avatar asked Jul 16 '14 08:07

greW


People also ask

How do I add an Add to Cart button to my WordPress site?

Go to Appearance -> Customize, then go to WooCommerce -> Add to Cart Buttons to choose your settings. Change the Add To Cart button text and/or select the other options on this screen.

How do I change the color of add to Cart button in WooCommerce?

Change WooCommerce Add to Cart button color throughout your site. The first way is clicking in Buttons > Background Color. Here, you can customize change the background color and text color of your Add to Cart button. But with this option, you will change the color of all buttons on all pages.


1 Answers

Well, you can do it with ajax, you can redirect it to - '?add-to-cart=' and the item will get into the cart. so you will be able to design you'r button however you want ..

like image 61
Danny Avatar answered Sep 29 '22 12:09

Danny