Tips and Tricks HQ Support Portal › Forums › Simple PayPal Shopping Cart › Simple Shopping Cart Tweaks › "Add to Cart" button not in "the_content"
Tagged: add to cart, custom fields, sidebar, the_content, the_excerpt
- This topic has 4 replies, 2 voices, and was last updated 14 years, 10 months ago by amin007.
-
AuthorPosts
-
January 20, 2010 at 4:51 am #676klmartinMember
Loving the plugin – wonderfully simple…..so I thought I’d make it more difficult.
Basically, I want to drop [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end] in as a value in a custom field and have the Add to Cart button show up in a sidebar where the other related custom fields are displayed.
I figured out how to alter line 1451 to move the button to the excerpt
‘add_filter(‘the_content’, ‘print_wp_cart_button_new’,11);’
to
‘add_filter(‘the_excerpt’, ‘print_wp_cart_button_new’,11);’
but I’d like to use the excerpt for something else…and excerpt.
Anyway to get the button in the sidebar?
January 20, 2010 at 5:35 am #17385amin007ParticipantYou don’t need to change the line… you can just add the following line and it will filter the content as well as the excerpt:
add_filter(‘the_excerpt’, ‘print_wp_cart_button_new’,11);
To display a button on the sidebar use the following PHP function (you can pass in the product name and price to the function):
<?php echo print_wp_cart_button_for_product(“PRODUCT-NAME”, “PRODUCT-PRICE”); ?>
January 20, 2010 at 7:06 pm #17386klmartinMemberThanks! I finally got it to work!
1. I added the line you suggested to the wp_shopping_cart.php file.
2. In each post I added custom fields with the key/name Price & Shipping
3. In my sidebar template I established the 3 following variables
<?php
$prodname = $post->post_title ;
$prodprice = get_post_meta($post->ID, 'Price', true);
$prodshipping = get_post_meta($post->ID, 'Shipping', true);
?>
4. Then added this line where I wanted to put the button in that same template file
<?php echo print_wp_cart_button_for_product($prodname, $prodprice, $prodshipping); ?>
This worked for me – I seriously doubt its totally correct by php or wordpress standards, so admin, feel free to correct.
Thanks again for a great and simple plugin.
KLM
January 20, 2010 at 8:23 pm #17387klmartinMemberProblem! Refreshing the page adds an item to the cart every time you refresh.
Any clues as to how this is happening?
January 21, 2010 at 2:15 am #17388amin007ParticipantWhen a HTTP POST operation is performed on a page (e.g add to cart operation) then refreshing the page right after that operation will repeat the same process thereby adding the same product again. This is why the browser gives you an warning when you refresh a page that is about to repeat an HTTP POST operation.
-
AuthorPosts
- You must be logged in to reply to this topic.