I am creating a custom theme for woocommerce and I need to be able to create a mini product display. I am having problems finding documentation on the woocommerce api. I have a comma delimited list of product IDs that I need to iterate through and display a custom mini product display for each in sequence.
$key_values = get_post_custom_values('rel_products_ids');
//get comma delimited list from product
$rel_product_ids = explode(",", trim($key_values, ","));
// create array of just the product ids
foreach ( $rel_product_ids as $pid ) {
//sequentially get each id and do something with it
$loop = new WP_Query( array( 'post__in' => $pid ) );
// also tried ...
//$loop = new WP_Query( array( 'ID' => $pid ) );
while ( $loop->have_posts() ) : $loop->the_post(); $_product = &new WC_Product( $loop->post->ID );
//do stuff here I have stripped the html in favor of getting to the meat of the issue
woocommerce_show_product_sale_flash( $post, $_product );
if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_single');
get_permalink( $loop->post->ID );
the_title();
$_product->get_price_html();
endwhile;
}
Any help would be appreciated.
Thank you,
Tim
Use this method:
Official API-docs: wc_get_product
Another easy way is to use the WC_Product_Factory class and then call function get_product(ID)
http://docs.woothemes.com/wc-apidocs/source-class-WC_Product_Factory.html#16-63
sample:
You can then use all the function calls as listed in their api:
http://docs.woothemes.com/wc-apidocs/class-WC_Product.html
Alright, I deserve to be throttled. definitely an RTM but not for WooCommerce, for WordPress.
Solution found due to a JOLT cola (all hail JOLT cola).
TASK:
Field named ‘related_product_ids’ added to a custom post type. So when that post is displayed mini product displays can be displayed with it.
PROBLEM:
Was having a problem getting the multiple ids returned via WP_Query.
SOLUTION:
Thank you for anyone who may have spent some time on this.
Tim