Wordpress搜索数据库值并返回
我一直在寻找一个可以在WordPress中做类似事情的代码,但它不能调用woocommerce 似乎什么都不管用Wordpress搜索数据库值并返回,wordpress,return,call,Wordpress,Return,Call,我一直在寻找一个可以在WordPress中做类似事情的代码,但它不能调用woocommerce 似乎什么都不管用 if get_post_meta( get_the_ID(), '_regular_price' is greater then 1) do this else do this code $my_post_meta=get_post_meta(get_ID(),'sale_price',true) 这对我有效这取决于您使用此功能的位置 假设您正在尝试编辑产品页面。在wooc
if
get_post_meta( get_the_ID(), '_regular_price' is greater then 1)
do this
else
do this code
$my_post_meta=get_post_meta(get_ID(),'sale_price',true)
这对我有效这取决于您使用此功能的位置 假设您正在尝试编辑产品页面。在woocommerce模板文件夹中,您可以找到例如:price.php 通常已经有一个全局变量可用,如果不可用,可以使用
global$product
进行设置。使用$product->get_id()
可以获取产品id
通过全局变量,销售价格可以像$price=$product->get_sale_price()一样使用代码>
为了生成if语句,您需要数据,以便进行下一步。也许由于某种原因,您的价格是空的,返回的是未定义的,这使得if语句很难执行
if (empty($price))
$price = 0;
if($price > 1))
// do your thing
if (empty($price))
$price = 0;
if($price > 1))
// do your thing