php - Woocommerce中可变产品的所有变体的总库存
问题描述
我尝试使用Get the total stock from a variable product In Woocommerce,试图使这段代码工作:
add_action( 'woocommerce_after_shop_loop_item_title', 'display_variable_product_stock_quantity', 20 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
有了这个:
add_action( 'woocommerce_single_product_summary', 'display_variable_product_stock_quantity', 15 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
或者是否可以在数量的默认元素中获得总库存?例如。股票将在下面突出显示:
解决方案
只需使用以下方法,以这种方式更改钩子(用于存档页面作为商店):
add_action( 'woocommerce_after_shop_loop_item', 'display_variable_product_stock_quantity', 20 );
function display_variable_product_stock_quantity(){
wc_get_variable_product_stock_quantity( 'echo_html' );
}
代码位于您的活动子主题(或活动主题)的 function.php 文件中。它应该按要求工作。
推荐阅读
- html - 标题元素一直显示在同一行
- ios - 视图内的图像显示底部空白
- authentication - 身份验证日志监控 GCP
- reactjs - FastAPI 会随着时间的推移减慢文件下载速度
- typescript - 来自键值对象的打字稿类型函数
- bash - 使用shell脚本通过pod登录的kubernetes redis-cluster pod?
- azure - 如何查看 CosmosDB 何时进行速率限制
- javascript - Android 上的 Cordova 插件错误 - cordova-plugin-secure-key-store
- java - JBOSS EAP 7.3:如何覆盖所有服务器或服务器组的 jboss.as.jpa.providerModule?
- django - 如何使用 Django 中的会话将所有表单数据从一个视图发送到另一个视图