php-如何在WooCommerce中为自定义产品类型启用价格和库存
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-如何在WooCommerce中为自定义产品类型启用价格和库存,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1769字,纯文字阅读大概需要3分钟。
内容图文
![php-如何在WooCommerce中为自定义产品类型启用价格和库存](/upload/InfoBanner/zyjiaocheng/685/c54ee085c36c486ea9716285132364ca.jpg)
我在WooCommerce应用程序中创建了自定义产品类型
function register_variable_bulk_product_type() {
class WC_Product_Variable_bulk extends WC_Product_Simple {
public function __construct($product) {
$this->product_type = 'variable_bulk';
parent::__construct($product);
}
}
}
add_action('init', 'register_variable_bulk_product_type');
function add_variable_bulk_product($types) {
$types['variable_bulk'] = __('Variable Bulk');
return $types;
}
add_filter('product_type_selector', 'add_variable_bulk_product');
这会在产品数据下拉列表中显示产品类型,如下所示,
我的问题是
新产品没有添加库存和价格的选项,如何启用这些选项?
解决方法:
You need a small JS trick to show Price and Inventory tab, i.e. you
need to add classshow_if_{your_custom_product_type}
in your case it
will beshow_if_variable_bulk
.
这是工作代码:
function wh_variable_bulk_admin_custom_js() {
if ('product' != get_post_type()) :
return;
endif;
?>
<script type='text/javascript'>
jQuery(document).ready(function () {
//for Price tab
jQuery('.product_data_tabs .general_tab').addClass('show_if_variable_bulk').show();
jQuery('#general_product_data .pricing').addClass('show_if_variable_bulk').show();
//for Inventory tab
jQuery('.inventory_options').addClass('show_if_variable_bulk').show();
jQuery('#inventory_product_data ._manage_stock_field').addClass('show_if_variable_bulk').show();
jQuery('#inventory_product_data ._sold_individually_field').parent().addClass('show_if_variable_bulk').show();
jQuery('#inventory_product_data ._sold_individually_field').addClass('show_if_variable_bulk').show();
});
</script>
<?php
}
add_action('admin_footer', 'wh_variable_bulk_admin_custom_js');
代码进入您的活动子主题(或主题)的functions.php文件中.或也在任何插件PHP文件中.
代码已经过测试并且可以正常工作.
这是您的常规标签的外观:
这是库存标签的外观
希望这可以帮助!
内容总结
以上是互联网集市为您收集整理的php-如何在WooCommerce中为自定义产品类型启用价格和库存全部内容,希望文章能够帮你解决php-如何在WooCommerce中为自定义产品类型启用价格和库存所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。