Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore Tweaks › Getting error – Function integration in PHP
- This topic has 3 replies, 2 voices, and was last updated 13 years, 4 months ago by
Libin V Babu.
-
AuthorPosts
-
June 27, 2012 at 6:50 am #6684
Libin V Babu
MemberHi, I’m using “More Fields” plugin to get custom date from the post. So I want to include the product id entered by the admin in more fields textbox. I’m using the below function in my template file.
<?php
$product_id = meta(‘product-id’);
echo show_wp_eStore_product_fancy($product_id,1,3);
?>
When I echo the $product_id separately, It prints the correct product id entered in text box. But when used in the function, It shows ” Looks like you have entered a product ID in the shortcode that doesn’t exist. Please check your product ID and the shortcode again! ” If I replace the “$product_id” with value, say 1, It will outputs the correct product.
How can I achieve this??
June 27, 2012 at 11:32 pm #46515admin
KeymasterI don’t know how that plugin is returning that product ID (the format is most likely not correct) but you don’t need another plugin to retrieve custom fields data of a post. You can use WordPress’s default function to do that. This post has examples that might help:
https://support.tipsandtricks-hq.com/forums/topic/call-product-through-a-custom-field
June 28, 2012 at 4:41 am #46516Libin V Babu
MemberThank you so much. That was really helpful. Now it is working.
I got the code to call the “add to cart” button from that topic.
<?php echo get_button_code_for_product($product_id); ?>I wants to include the products details at different places in my template. So How can I display a product’s name, price, availability separately with the product_id?
I tried to do this:
$product_name = $wpdb->query($wpdb->prepare( "SELECT name FROM wp_wp_eStore_tbl WHERE id ='$product_id'"));
echo $product_name;
But it is not working.
June 28, 2012 at 11:31 am #46517Libin V Babu
MemberGot it.
$product_name = $wpdb->get_results( "SELECT * FROM wp_wp_eStore_tbl WHERE id ='$product_id'");
foreach ($product_name as $row)
{
echo $row->name;
}
Its working fine. Hope the usage is correct.
-
AuthorPosts
- You must be logged in to reply to this topic.