通过id
1 个回答
- 投票数
-
- 2018-03-08
您可以使用以下功能创建产品对象:
$product = wc_get_product( $post_id );
然后,您将可以访问所有产品的数据.您可以在此处找到所有可用方法,但您需要的是:
$product->get_regular_price(); $product->get_sale_price(); $product->get_price();
You can create a product object using the following function:
$product = wc_get_product( $post_id );
And after that you will be able to access to all product's data. All available methods can be found here, but the ones you need are:
$product->get_regular_price(); $product->get_sale_price(); $product->get_price();
-
谢谢您的回复.我已经看了.再次检查.但是为此,我需要以不同的方式更改我的简码功能.我对吗?无论如何我的简码内thanks for reply. i look that already. checking again. but for that i need to change my shortcode function different way. am i right ? is there anyway to do inside my shortcode
- 0
- 2018-03-08
- Accore LTD
-
只需在$price上方的某个地方添加$product=wc_get_product($post_id);并设置$price=$product->get_price().Just add `$product = wc_get_product( $post_id );` somewhere above $price and set `$price = $product->get_price()`.
- 1
- 2018-03-08
- Boris Kuzmanov
-
这使我的本地崩溃This crashed my local
- 1
- 2018-08-23
- Ashwani Shukla
我用一个简码来获取产品标题,图像和价格.我正在正确获取所有标题,链接和图像,但没有得到价格.但问题是
$price = get_the_price($post_id);
我猜这个函数不正确任何想法如何立即获得价格.
谢谢