WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Simple Paypal Shopping Cart
[resolved] Custom code question: (16 posts)

  1. Teratoma
    Member
    Posted 2 years ago #

    I'm still pretty noobish when it comes to this stuff but I can't tell what's wrong with my code. I'll try to explain what I'm doing. I put some code in a widget that pulled the_title into the 'PRODUCT-NAME' section of the 'add to cart' button, and charge $10 for the item. I was pleased with myself. Then I got really crazy and decided I could use get_post_custom_values for the 'ITEM-PRICE' code the same way. So I added a custom field called 'price', added prices to a couple of items, then tested the button. It displayed this in the sidebar:

    Warning: number_format() expects parameter 1 to be double, string given in XXXXXXXXXX/wordpress-simple-paypal-shopping-cart/wp_shopping_cart.php on line 321

    The following is my code:

    <?php
    $productid = get_the_title();
    $price = get_post_custom_values('Price');
    echo print_wp_cart_button_for_product("$productid", "$price"); ?>

    I'm doing something silly aren't I? Please tell me I'm close!

    This is one of the posts: http://pins.kevinbyrd.co/vc033008/

    The post titles are the product IDs. Right now everything's ten bucks anyway so that's just a text string currently, but I'd like to be able to use that variable.

    http://wordpress.org/extend/plugins/wordpress-simple-paypal-shopping-cart/

  2. jamesgentry
    Member
    Posted 2 years ago #

    I had to change:
    <?php echo print_wp_cart_button_for_product("$productid", "$price"); ?>
    to:
    <?php echo print_wp_cart_button_for_product("$productid", "$price[0]"); ?>

    and it worked great.

  3. Teratoma
    Member
    Posted 2 years ago #

    Excellent! Now I just set the prices as I post - or in bulk using any number of plugins - and never have to worry about the button again.

    Thanks for the help!

  4. speedyp
    Member
    Posted 2 years ago #

    Just stumbled across this post - it's exactly what I'm trying to do: tie a couple of custom fields into the add to cart button.

    I have very little experience with these things, but so far I've used the Advanced Custom Fields plugin to generate price and product description.

    I love the way you are getting the product title from the post title, but could really use some help with adding the price bit please.

    I can get the price with acf by using:'<?php the_field('price'); ?>'
    But I need help adapting your code to use this??

    Thanks

  5. speedyp
    Member
    Posted 2 years ago #

    Well this sort of works, but it just gets the first number in the price
    eg. 32.00 shows as 3 in the checkout?

    '<?php
    $productid = get_the_title();
    $price = get_field('price');
    echo print_wp_cart_button_for_product("$productid", "$price"); ?>'

  6. Teratoma
    Member
    Posted 2 years ago #

    Hi speedyp! I'm glad you like the idea. I created a plugin that adds this functionality to a couple of widgets.

    You can see it in action here:

    http://pins.KevinByrd.co/boards/sales

    And download it here:

    http://KevinByrd.co/wp

    I was planning on ironing out the bugs (the shortcodes perform poorly but the widgets work great!) before releasing it, but I figured I'd share it. Let me know if you get any use out of it!

    Cheers!

  7. deepbevel
    Member
    Posted 1 year ago #

    seems there's a possible malware attack on that url..for me anyway!

    but, just wanted to thank the posters for this info, can't get the price dynamically yet but just getting the title is saving my client a load of time.. thanks!

  8. Teratoma
    Member
    Posted 1 year ago #

    Malware? On my site, or on the Adfly link? I can assure you that my site is safe - a typical WordPress install. If you mean Adfly, I think you should be pretty safe as long as you avoid ALL links on the page except for the 'skip ad' in the upper right.

    That said, I've been using Github a lot lately so here's a 100% safe source with no ads or other bs: https://github.com/Teratoma/teratomic-paypal-button

    What issues are you having with the price? The readme assumes you know how to set custom fields, is that the problem?

  9. deepbevel
    Member
    Posted 1 year ago #

    I'll try it, yes I have the fields, at one point I was using a custom field for the title, it was working!.. but I couldn't get my custom field for the price to output. I tried all of the above and then some. In the process I lost the ability to use the custom field for the item title. Now I keep getting the

    Warning: number_format() expects parameter 1 to be double, string given in XXXXXXXXXX/wordpress-simple-paypal-shopping-cart/wp_shopping_cart.php on line 321

    error.

    I'm checking out different posts and I see there are different ways of calling the post fields and different params for the product settings, none of it is working, I'm getting confused..

    I hope the plugin helps,thanks!

  10. deepbevel
    Member
    Posted 1 year ago #

    arrg, my fields are in the attachment post type. is their a way to get it to add the field there instead of the post?

  11. deepbevel
    Member
    Posted 1 year ago #

    otherwise, if anyone has a currently working example of using custom fields for the title and price values, I had it for the title, now I can't remember how I did it and none of the examples are working.

  12. deepbevel
    Member
    Posted 1 year ago #

    @teratoma
    the malware wasn't on your site, but the download link.
    http://adf.ly/BxBWP

  13. deepbevel
    Member
    Posted 1 year ago #

    okay, got it working for the product id again,

    <?php
    $productid =  get_post_meta($post->ID,'size_format_1',true);
    $price = '200';
    echo print_wp_cart_button_for_product("$productid", "$price"); ?>

    price is still hardcoded, still seeking a dynamic solution for that..

  14. deepbevel
    Member
    Posted 1 year ago #

    FIXED!
    the solution was the error message of course, the numeric param in the field had to be like this(for 200 dollars)

    200,00

    also had to remove[0] from "$price"

    working code:

    <?php
    $productid =  get_post_meta($post->ID,'size_format_1',true); 
    
    $price = get_post_meta($post->ID,'price_1',true); 
    
    $shipping ='15';
    
    echo print_wp_cart_button_for_product("$productid", "$price", "$shipping"); ?>

    shipping is still not dynamic but I'll settle for now.

    thanks again to the thread authors!

  15. deepbevel
    Member
    Posted 1 year ago #

    Shipping is now working too!
    I just used the same get_post_meta but with the custom field value I made for shipping.

    Seems the fields must be "required" in order for this to work, not sure if that's only because I'm using the "advanced custom fields" plugin to get my fields.. it has a "required" option for the value to be filled, and it must be set as true.

    This may be why I was getting that error, I selected "required" as true for the fields when I changed my numeric values to the "00,00" format, so I have to test to see which was causing the error, maybe both!

  16. deepbevel
    Member
    Posted 1 year ago #

    actually, it looks as though it could be neither. I think all I had to do was update the post after adding the default values in "advanced customfields".. I assumed they would apply since they are default, but looks like the post doesn't know it has them untill it's updated.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags