bmex63

WooCommerce Tab 3

Jul 5th, 2012
210
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Custom Tabs for Custom Specifications 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_spec() {
  9. ?>
  10.     <li class="custom_tab3"><a href="#custom_tab_data3"><?php _e('Custom Tab 3', 'woothemes'); ?></a></li>
  11. <?php
  12. }
  13. add_action('woocommerce_product_write_panel_tabs', 'custom_tab_options_tab_spec');
  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_spec() {
  22.     global $post;
  23.    
  24.     $custom_tab_options_spec = array(
  25.         'titlec' => get_post_meta($post->ID, 'custom_tab_title_spec', true),
  26.         'contentc' => get_post_meta($post->ID, 'custom_tab_content_spec', true),
  27.     );
  28.    
  29. ?>
  30.     <div id="custom_tab_data3" 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_spec', '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_spec" value="<?php echo @$custom_tab_options_spec['titlec']; ?>" 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_spec',
  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_spec-editor-container .wp-editor-area{height:250px; width:100%;} #custom_tab_data3 .quicktags-toolbar input {width:auto;}</style>'
  59.                         );
  60.                        
  61.         $id = 'custom_tab_content_spec';
  62.  
  63.  wp_editor($custom_tab_options_spec['contentc'],$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_spec');
  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_spec( $post_id ) {
  82.     update_post_meta( $post_id, 'custom_tab_enabled_spec', ( isset($_POST['custom_tab_enabled_spec']) && $_POST['custom_tab_enabled_spec'] ) ? 'yes' : 'no' );
  83.     update_post_meta( $post_id, 'custom_tab_title_spec', $_POST['custom_tab_title_spec']);
  84.     update_post_meta( $post_id, 'custom_tab_content_spec', $_POST['custom_tab_content_spec']);
  85. }
  86. add_action('woocommerce_process_product_meta', 'process_product_meta_custom_tab_spec');
  87.  
  88.  
  89. /** Add extra tabs to front end product page **/
  90. if (!function_exists('woocommerce_product_custom_tab_spec')) {
  91.     function woocommerce_product_custom_tab_spec() {
  92.         global $post;
  93.        
  94.         $custom_tab_options_spec = array(
  95.             'enabled' => get_post_meta($post->ID, 'custom_tab_enabled_spec', true),
  96.             'titlec' => get_post_meta($post->ID, 'custom_tab_title_spec', true),
  97.         );
  98.        
  99.         if ( $custom_tab_options_spec['enabled'] != 'yes' )
  100.             return false;
  101.        
  102. ?>
  103.         <li><a href="#tab-spec"><?php echo $custom_tab_options_spec['titlec']; ?></a></li>
  104. <?php
  105.     }
  106. }
  107. add_action( 'woocommerce_product_tabs', 'woocommerce_product_custom_tab_spec', 16 );
  108.  
  109.  
  110. if (!function_exists('woocommerce_product_custom_panel_spec')) {
  111.     function woocommerce_product_custom_panel_spec() {
  112.         global $post;
  113.        
  114.         $custom_tab_options_spec = array(
  115.             'titlec' => get_post_meta($post->ID, 'custom_tab_title_spec', true),
  116.             'contentc' => get_post_meta($post->ID, 'custom_tab_content_spec', true),
  117.         );
  118.        
  119. ?>
  120.         <div class="panel" id="tab-spec">          
  121.             <?php echo $custom_tab_options_spec['contentc']; ?>
  122.         </div>
  123. <?php
  124.     }
  125. }
  126. add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_custom_panel_spec', 16 );
  127.  
  128. ?>
RAW Paste Data