我想以编程方式将设置选项卡添加到产品数据元变量,如下所示:
"Verzendkosten"选项卡添加了firebug (意思是"运费").
如何在woocommerce编辑产品页面设置中以编程方式添加"Verzendkosten"自定义选项卡?
(以及我如何能够用数据填充它?)
我正在尝试将复选框添加到 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吗?