php - Woocommerce Get Product Values by ID -
trying product data on custom template product id, right have code product title.
$productid = 164; echo $p_title = get_the_title( $productid );
looking short description, price, product image, product url, product brand. or might loop better loop should work product static id.
thanks in advance.
you better served creating new product object.
$productid = 164; $product = wc_get_product( $productid ); echo $product->get_title(); echo $product->get_price_html();
note, short description merely post's post_excerpt
. if using outside of loop (where $post
automatically defined) need post directly.
$post = get_post( $productid ); echo apply_filters( 'woocommerce_short_description', $post->post_excerpt );
or alternatively, if you've defined product object do
echo apply_filters( 'woocommerce_short_description', $product->post->post_excerpt );
since woocommerce product class automatically define $product->post
property get_post()
.
apply_filters()
means functions can attached @ point modify content of $product->post->post_content
. @ minimum, know wpautop()
attached woocommerce_short_description
filter create paragraph breaks.
Comments
Post a Comment