質問

i am very new wooCommerce and WordPress. programming knowledge not strong yet. but for my project i need to do something. now i want to create custom short code for woocommerce product.

i want to show product by id or sku. woocommerce built-in shortcodes have and it is working fine which is https://docs.woothemes.com/document/woocommerce-shortcodes/ but example [product id="99"] but if use this shortcodes then it come with add to cart price etc information. mean template take for product. but i want to show only thumbnail picture and name and link. how can i do that ? can do anything in function.php for this. or create separate shortcodes for this.

would you guys help me out . how can i do that.

Thanks

役に立ちましたか?

解決

Hello Here is the Shortcode you can use this it will give you title link and image of product. Put this code in functions.php file of your theme.

add_shortcode('product_data','custom_product_function');
function custom_product_function($atts)
{
    $post_id = $atts['id'];
    $title = get_the_title($post_id);
    $link = get_the_permalink($post_id);
    $image = get_the_post_thumbnail($post_id);
    $data ='<div><a href="'.$link.'"><p>'.$title.'</p></a>'.
    $image.'</div>';
    return $data;
}

And then add the shortcode in your page or post with product id

[product_data id=1958]

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top