- This topic has 2 replies, 2 voices, and was last updated 14 years, 4 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Support site for Tips and Tricks HQ premium products
by
Tips and Tricks HQ Support Portal › Forums › Simple PayPal Shopping Cart › Simple Shopping Cart Tweaks › Get PRODUCT NAME from title attribute and PRICE from custom field?
Tagged: costum post type, custom field, name, price
I’m creating an art store using a Custom Post type and a custom field to handle the price. What I would like to do is use this code to create the “add to cart” button in the store’s template:
<?php echo print_wp_cart_button_for_product(’PRODUCT-NAME’, PRODUCT-PRICE); ?>
Using this code, is there a way to pull the product name from the title of the post and the price from the custom field? Is there any other way to achieve this? I’m running this store with several other artists who are not code-savvy, so to speak, so I’m trying to avoid them having to use the shortcode when they add an item.
Yeah, you should be able to do it. This post should help you with getting the custom field information:
coding question for simple cart wp plugin with custom field template plugin
Given that you are calling that function form the WordPress loop you can use the following code to get the title of the post:
<?php
$title = the_title();
echo print_wp_cart_button_for_product($title,"15.95");
?>
You can also query WordPress to get the information of an individual post from anywhere on your blog. This post has more info on this:
http://www.tipsandtricks-hq.com/query-or-show-a-specific-post-in-wordpress-php-code-example-44
Thanks! That first link did exactly what I was looking for.