Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore Tweaks › Call product through a custom field
Tagged: custom field, custom themes, hacks, product
- This topic has 3 replies, 2 voices, and was last updated 15 years ago by amin007.
-
AuthorPosts
-
November 10, 2009 at 7:27 am #408zacMember
Any thoughts how I could have the product info called through a custom field ? Because of the way I am trying to design the template, this would be ideal for me as I want the products to not be a part of the_content. I just tried something like
<?php if ( get_post_meta($post->ID, ‘productOne’, true) ) { ?>
<?php echo get_post_meta($post->ID, “productOne”, $single = true); ?>”>
<?php } ?>
with this as the field : [wp_eStore:product_id:2:end]
but it didnt work.. any way I could accomplish this ? Thanks.
November 10, 2009 at 8:40 am #15910amin007Participant@Zac, the shortcodes work on wordpress post or page not on template files. So you need to call the PHP appropriate PHP file to create the Add to Cart button. Have a look at the available PHP function in the PHP function references list:
http://www.tipsandtricks-hq.com/ecommerce/wp-content/uploads/2009/09/wp-estore-shortcodes.pdf
Or you can use the do_shortcode() function and pass the shortcode through it.
November 11, 2009 at 4:14 am #15911zacMemberThank you for the reply. Not quite what I need but closer… would it be possible you think for me to use the custom field just to put in the product id? Something like:
<?php if ( get_post_meta($post->ID, ‘productOne’, true) ) { ?>
<?php echo get_button_code_for_product(<?php echo get_post_meta($post->ID, “productOne”, $single = true); ?>”>); ?>
<?php } ?>
Then the custom field the client could just enter their product number.. would this work ??
… well I know that doesnt work… but something like that.. I am not sure how to write the php… or if it is possible ??
November 11, 2009 at 7:52 am #15912amin007ParticipantYep, something like this should definitely work.. do a test like the following:
<?php
if (get_post_meta($post->ID, 'productOne', true))
{
//first check to make sure you are getting the product id of the product
$product_id = get_post_meta($post->ID, 'productOne', true);
echo $product_id;
//then pass the product id to the function
echo get_button_code_for_product($product_id); ?>
}
?>This way you will be able to see which part isn’t working
Another related post:
https://support.tipsandtricks-hq.com/forums/topic/custom-fields-within-php-shortcodes
-
AuthorPosts
- You must be logged in to reply to this topic.