相关疑难解决方法(0)

以编程方式添加自定义设置选项卡以管理WooCommerce中的产品数据

我想以编程方式将设置选项卡添加到产品数据元变量,如下所示:

在此输入图像描述

"Verzendkosten"选项卡添加了firebug (意思是"运费").

如何在woocommerce编辑产品页面设置中以编程方式添加"Verzendkosten"自定义选项卡?

(以及我如何能够用数据填充它?)

php wordpress product meta-boxes woocommerce

4
推荐指数
1
解决办法
1809
查看次数

Woocommerce中管理员编辑产品的复选框自定义字段

我正在尝试将复选框添加到 WooCommerce(在管理面板中)的设置选项卡并使用以下代码:

add_action( 'woocommerce_product_options_general_product_data', 'wc_custom_add_custom_fields' );
function wc_custom_add_custom_fields() {    
    global $post;
    woocommerce_wp_checkbox(array( 
        'id'            => 'is_gift', 
        'label'         => __('Gift', 'woocommerce' ), 
        'description'   => __( 'Add gift label', 'woocommerce' ),
        'value'         => get_post_meta($post->ID, 'is_gift', true) 
    ));
}

add_action( 'woocommerce_process_product_meta', 'wc_custom_save_custom_fields' );
function wc_custom_save_custom_fields() {
    global $post;
    if (!empty($_POST['is_gift'])) {
        update_post_meta( $post->ID, 'is_gift', esc_attr( $_POST['is_gift'] ) );       
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码显示复选框,但不保存更改。它仅适用于一种产品。我猜有什么问题$post->ID吗?

wordpress checkbox product woocommerce hook-woocommerce

2
推荐指数
1
解决办法
2413
查看次数