我已经添加了一个自定义产品类型到我的woocommerce网站称为“礼品卡”,并启用“库存”产品数据选项卡使用以下代码:
// Register the product type
function register_product_type () {
class WC_Product_Gift_Card extends WC_Product {
public function __construct( $product ) {
$this->product_type = 'gift_card';
parent::__construct( $product );
// add additional functions here
}
}
}
add_action( 'init', 'register_product_type' );
// Add the product type to the dropdown select
function add_product_type ( $type ) {
$type[ 'gift_card' ] = __( 'Gift Card' );
return $type;
}
add_filter( 'product_type_selector', 'add_product_type' );
// Show the "Inventory" tab and hide the "Shipping" tab
function product_data_tabs( $tabs ) {
global $post, $product_object;
if ( $product_object && $product_object->is_type( 'gift_card' ) ) {
$tabs['inventory']['class'][] = 'show_if_gift_card';
unset( $tabs['shipping'] );
}
return $tabs;
}
add_filter( 'woocommerce_product_data_tabs', 'product_data_tabs', 10, 1 );
但是,在库存选项卡上,没有显示“管理库存水平(数量)”选项。我尝试用下面的代码启用它,但它抛出了一个错误:
function show_manage_stock_options( $panels ) {
global $product_object;
if ( $product_object && $product_object->is_type( 'gift_card' ) ) {
$inventory_panel = $panels['inventory'];
$inventory_panel['fields']['manage_stock']['class'][] = 'show_if_gift_card';
$inventory_panel['fields']['stock_quantity']['class'][] = 'show_if_gift_card';
$panels['inventory'] = $inventory_panel;
}
return $panels;
}
add_filter( 'woocommerce_product_data_panels', 'show_manage_stock_options', 10, 2 );
我哪里做错了?
1条答案
按热度按时间093gszye1#
就用javascript来处理它