Skip to content

Instantly share code, notes, and snippets.

@shangdev
Last active November 30, 2018 07:43
Show Gist options
  • Save shangdev/95141d4ebcf4f4b6e0d8e2667ca2a96c to your computer and use it in GitHub Desktop.
Save shangdev/95141d4ebcf4f4b6e0d8e2667ca2a96c to your computer and use it in GitHub Desktop.
Add custom product data tab with options in woocommerce
<?php
/**
* Manage product data.
*
* @link https://rudrastyh.com/woocommerce/product-data-metabox.html
*
* @package Trueniu
* @subpackage WP Rig
* @since 1.0.0
*/
/**
* Create tab.
*
* @param array $tabs The product data tabs.
*
* @return mixed
*/
function wprig_product_data_tabs( $tabs ) {
$tabs['parameter'] = [
'label' => '型号',
'target' => 'wprig_product_parameter',
'class' => [],
'priority' => 15,
];
return $tabs;
}
add_filter( 'woocommerce_product_data_tabs', 'wprig_product_data_tabs' );
/**
* Tab content.
*/
function wprig_product_data_panels() {
global $post;
echo '<div id="wprig_product_parameter" class="panel woocommerce_options_panel hidden">';
woocommerce_wp_text_input( [
'id' => 'misha_plugin_version',
'value' => get_post_meta( $post->ID, 'misha_plugin_version', true ),
'label' => 'Plugin version',
'description' => 'Description when desc_tip param is not true',
] );
woocommerce_wp_textarea_input( [
'id' => 'misha_changelog',
'value' => get_post_meta( $post->ID, 'misha_changelog', true ),
'label' => 'Changelog',
'desc_tip' => true,
'description' => 'Prove the plugin changelog here',
] );
woocommerce_wp_select( [
'id' => 'misha_ext',
'value' => get_post_meta( $post->ID, 'misha_ext', true ),
'wrapper_class' => 'show_if_downloadable',
'label' => 'File extension',
'options' => [
'' => 'Please select',
'zip' => 'Zip',
'gzip' => 'Gzip',
],
] );
echo '</div>';
}
add_action( 'woocommerce_product_data_panels', 'wprig_product_data_panels' );
/**
* Save.
*/
function wprig_product_data_precess() {
}
add_action( 'woocommerce_process_product_meta', 'wprig_product_data_precess' );
/**
* Style.
*/
function wprig_product_data_style() {
?>
<style>
#woocommerce-product-data ul.wc-tabs li.parameter_options.parameter_tab a:before{
content: "\f203";
}
</style>
<?php
}
add_action( 'admin_head', 'wprig_product_data_style' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment