Advertisement
bmex63

WooCommerce Custom Product Tab 1

Jun 22nd, 2012
1,430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.60 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Custom Tab for Product display
  5.  *
  6.  * Outputs an extra tab to the default set of info tabs on the single product page.
  7.  */
  8. function custom_tab_options_tab() {
  9. ?>
  10.     <li class="custom_tab"><a href="#custom_tab_data"><?php _e('Custom Tab', 'woothemes'); ?></a></li>
  11. <?php
  12. }
  13. add_action('woocommerce_product_write_panel_tabs', 'custom_tab_options_tab');
  14.  
  15.  
  16. /**
  17.  * Custom Tab Options
  18.  *
  19.  * Provides the input fields and add/remove buttons for custom tabs on the single product page.
  20.  */
  21. function custom_tab_options() {
  22.     global $post;
  23.    
  24.     $custom_tab_options = array(
  25.         'title' => get_post_meta($post->ID, 'custom_tab_title', true),
  26.         'content' => get_post_meta($post->ID, 'custom_tab_content', true),
  27.     );
  28.    
  29. ?>
  30.     <div id="custom_tab_data" class="panel woocommerce_options_panel">
  31.         <div class="options_group">
  32.             <p class="form-field">
  33.                 <?php woocommerce_wp_checkbox( array( 'id' => 'custom_tab_enabled', 'label' => __('Enable Custom Tab?', 'woothemes'), 'description' => __('Enable this option to enable the custom tab on the frontend.', 'woothemes') ) ); ?>
  34.             </p>
  35.         </div>
  36.        
  37.         <div class="options_group custom_tab_options">                                             
  38.             <p class="form-field">
  39.                 <label><?php _e('Custom Tab Title:', 'woothemes'); ?></label>
  40.                 <input type="text" size="5" name="custom_tab_title" value="<?php echo @$custom_tab_options['title']; ?>" placeholder="<?php _e('Enter your custom tab title', 'woothemes'); ?>" />
  41.             </p>
  42.            
  43.             <p class="form-field">
  44.                 <?php _e('Custom Tab Content:', 'woothemes'); ?>
  45.             </p>
  46.            
  47.             <table class="form-table">
  48.                 <tr>
  49.                     <td>
  50.                         <textarea class="theEditor" rows="10" cols="40" name="custom_tab_content" placeholder="<?php _e('Enter your custom tab content', 'woothemes'); ?>"><?php echo @$custom_tab_options['content']; ?></textarea>
  51.                     </td>
  52.                 </tr>  
  53.             </table>
  54.         </div> 
  55.     </div>
  56. <?php
  57. }
  58. add_action('woocommerce_product_write_panels', 'custom_tab_options');
  59.  
  60.  
  61. /**
  62.  * Process meta
  63.  *
  64.  * Processes the custom tab options when a post is saved
  65.  */
  66. function process_product_meta_custom_tab( $post_id ) {
  67.     update_post_meta( $post_id, 'custom_tab_enabled', ( isset($_POST['custom_tab_enabled']) && $_POST['custom_tab_enabled'] ) ? 'yes' : 'no' );
  68.     update_post_meta( $post_id, 'custom_tab_title', $_POST['custom_tab_title']);
  69.     update_post_meta( $post_id, 'custom_tab_content', $_POST['custom_tab_content']);
  70. }
  71. add_action('woocommerce_process_product_meta', 'process_product_meta_custom_tab');
  72.  
  73.  
  74. /** Add extra tabs to front end product page **/
  75. if (!function_exists('woocommerce_product_custom_tab')) {
  76.     function woocommerce_product_custom_tab() {
  77.         global $post;
  78.        
  79.         $custom_tab_options = array(
  80.             'enabled' => get_post_meta($post->ID, 'custom_tab_enabled', true),
  81.             'title' => get_post_meta($post->ID, 'custom_tab_title', true),
  82.         );
  83.        
  84.         if ( $custom_tab_options['enabled'] != 'yes' )
  85.             return false;
  86.        
  87. ?>
  88.         <li><a href="#tab-models"><?php echo $custom_tab_options['title']; ?></a></li>
  89. <?php
  90.     }
  91. }
  92. add_action( 'woocommerce_product_tabs', 'woocommerce_product_custom_tab', 11 );
  93.  
  94.  
  95. if (!function_exists('woocommerce_product_custom_panel')) {
  96.     function woocommerce_product_custom_panel() {
  97.         global $post;
  98.        
  99.         $custom_tab_options = array(
  100.             'title' => get_post_meta($post->ID, 'custom_tab_title', true),
  101.             'content' => get_post_meta($post->ID, 'custom_tab_content', true),
  102.         );
  103.        
  104. ?>
  105.         <div class="panel" id="tab-models">        
  106.             <?php echo $custom_tab_options['content']; ?>
  107.         </div>
  108. <?php
  109.     }
  110. }
  111. add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_custom_panel', 11 );
  112.  
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement