wordpress - 在 WooCommerce 中按产品 ID 显示带有简码的产品价格
问题描述
我正在尝试创建一个简码来使用它的 ID 显示 woocommerce 产品的价格
我正在使用这段代码:
/**
* Shortcode WooCommerce Product Price.
*
*/
function cl_woo_product_price_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => null
), $atts, 'cl_product_price' );
if ( empty( $atts[ 'id' ] ) ) {
return '';
}
$product = wc_get_product( $atts['id'] );
if ( ! $product ) {
return '';
}
return $product->get_price();
}
但它没有在开头显示 $ 符号,我还想添加一些 CSS。
你可以帮帮我吗?太感谢了!
解决方案
推荐阅读
- android - Idea android sdk设置
- python - 如何在 Python 中动态创建 Pandas 系列?
- javascript - 代码执行时间限制
- react-native - 如何在反应导航中将抽屉放在标题上?
- php - 替换方框字符
- java - Java 9+,通过反射调用 Map.Entry::getValue
- java - 使用 Spring Boot 将数据插入关系表(多对多)
- python - 在 IronPython 中出现错误“没有名为线程的模块”
- java - 边距 8 dp 随处可见,上、右、左和下
- regex - jdownloader2 导入带有链接的 txt 文件(正则表达式)