bmex63

WooCommerce Custom Product Tab with TinyMCE

Jun 22nd, 2012
772
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Custom Tab for Product display with TinyMCE Editor
  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. <?php
  51.         $settings = array(
  52.                         'text_area_name'=> 'custom_tab_content',
  53.                         'quicktags'     => true,
  54.                         'tinymce'       => true,
  55.                         'media_butons'  => false,
  56.                         'textarea_rows' => 98,
  57.                         'editor_class'  => 'contra',
  58.                         'editor_css'    => '<style>#wp-custom_tab_content-editor-container .wp-editor-area{height:250px; width:100%;} #custom_tab_data .quicktags-toolbar input {width:auto;}</style>'
  59.                         );
  60.                        
  61.         $id = 'custom_tab_content';
  62.  
  63.  wp_editor($custom_tab_options['content'],$id,$settings);
  64.  
  65.  ?>
  66.                     </td>
  67.                 </tr>  
  68.             </table>
  69.         </div> 
  70.     </div>
  71. <?php
  72. }
  73. add_action('woocommerce_product_write_panels', 'custom_tab_options');
  74.  
  75.  
  76. /**
  77.  * Process meta
  78.  *
  79.  * Processes the custom tab options when a post is saved
  80.  */
  81. function process_product_meta_custom_tab( $post_id ) {
  82.     update_post_meta( $post_id, 'custom_tab_enabled', ( isset($_POST['custom_tab_enabled']) && $_POST['custom_tab_enabled'] ) ? 'yes' : 'no' );
  83.     update_post_meta( $post_id, 'custom_tab_title', $_POST['custom_tab_title']);
  84.     update_post_meta( $post_id, 'custom_tab_content', $_POST['custom_tab_content']);
  85. }
  86. add_action('woocommerce_process_product_meta', 'process_product_meta_custom_tab');
  87.  
  88.  
  89. /** Add extra tabs to front end product page **/
  90. if (!function_exists('woocommerce_product_custom_tab')) {
  91.     function woocommerce_product_custom_tab() {
  92.         global $post;
  93.        
  94.         $custom_tab_options = array(
  95.             'enabled' => get_post_meta($post->ID, 'custom_tab_enabled', true),
  96.             'title' => get_post_meta($post->ID, 'custom_tab_title', true),
  97.         );
  98.        
  99.         if ( $custom_tab_options['enabled'] != 'yes' )
  100.             return false;
  101.        
  102. ?>
  103.         <li><a href="#tab-models"><?php echo $custom_tab_options['title']; ?></a></li>
  104. <?php
  105.     }
  106. }
  107. add_action( 'woocommerce_product_tabs', 'woocommerce_product_custom_tab', 11 );
  108.  
  109.  
  110. if (!function_exists('woocommerce_product_custom_panel')) {
  111.     function woocommerce_product_custom_panel() {
  112.         global $post;
  113.        
  114.         $custom_tab_options = array(
  115.             'title' => get_post_meta($post->ID, 'custom_tab_title', true),
  116.             'content' => get_post_meta($post->ID, 'custom_tab_content', true),
  117.         );
  118.        
  119. ?>
  120.         <div class="panel" id="tab-models">        
  121.             <?php echo $custom_tab_options['content']; ?>
  122.         </div>
  123. <?php
  124.     }
  125. }
  126. add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_custom_panel', 11 );
  127.  
  128. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×