Advertisement
bmex63

WooCommerce Custom Product Tab for WP Download Monitor

Jun 22nd, 2012
3,298
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Custom Tabs for Downloads Display using Shortcode
  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_down() {
  9. ?>
  10.     <li class="custom_tab2"><a href="#custom_tab_data2"><?php _e('Custom Tab 2', 'woothemes'); ?></a></li>
  11. <?php
  12. }
  13. add_action('woocommerce_product_write_panel_tabs', 'custom_tab_options_tab_down');
  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_down() {
  22.     global $post;
  23.    
  24.     $custom_tab_options_down = array(
  25.         'titleb' => get_post_meta($post->ID, 'custom_tab_title_down', true),
  26.         'contentb' => get_post_meta($post->ID, 'custom_tab_content_down', true),
  27.     );
  28.    
  29. ?>
  30.     <div id="custom_tab_data2" 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_down', '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_down" value="<?php echo @$custom_tab_options_down['titleb']; ?>" 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_down" placeholder="<?php _e('Enter your custom tab content', 'woothemes'); ?>"><?php echo @$custom_tab_options_down['contentb']; ?></textarea>
  51.                     </td>
  52.                 </tr>  
  53.             </table>
  54.         </div> 
  55.     </div>
  56. <?php
  57. }
  58. add_action('woocommerce_product_write_panels', 'custom_tab_options_down');
  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_down( $post_id ) {
  67.     update_post_meta( $post_id, 'custom_tab_enabled_down', ( isset($_POST['custom_tab_enabled_down']) && $_POST['custom_tab_enabled_down'] ) ? 'yes' : 'no' );
  68.     update_post_meta( $post_id, 'custom_tab_title_down', $_POST['custom_tab_title_down']);
  69.     update_post_meta( $post_id, 'custom_tab_content_down', $_POST['custom_tab_content_down']);
  70. }
  71. add_action('woocommerce_process_product_meta', 'process_product_meta_custom_tab_down');
  72.  
  73.  
  74. /** Add extra tabs to front end product page **/
  75. if (!function_exists('woocommerce_product_custom_tab_down')) {
  76.     function woocommerce_product_custom_tab_down() {
  77.         global $post;
  78.        
  79.         $custom_tab_options_down = array(
  80.             'enabled' => get_post_meta($post->ID, 'custom_tab_enabled_down', true),
  81.             'titleb' => get_post_meta($post->ID, 'custom_tab_title_down', true),
  82.         );
  83.        
  84.         if ( $custom_tab_options_down['enabled'] != 'yes' )
  85.             return false;
  86.        
  87. ?>
  88.         <li><a href="#tab-downloads"><?php echo $custom_tab_options_down['titleb']; ?></a></li>
  89. <?php
  90.     }
  91. }
  92. add_action( 'woocommerce_product_tabs', 'woocommerce_product_custom_tab_down', 24 );
  93.  
  94.  
  95. if (!function_exists('woocommerce_product_custom_panel_down')) {
  96.     function woocommerce_product_custom_panel_down() {
  97.         global $post;
  98.        
  99.         $custom_tab_options_down = array(
  100.             'titleb' => get_post_meta($post->ID, 'custom_tab_title_down', true),
  101.         );
  102.        
  103.         $downloads = get_post_meta($post->ID, 'custom_tab_content_down', true);
  104.         $nsoutput = do_shortcode( $downloads ) ;
  105.        
  106. ?>
  107.         <div class="panel" id="tab-downloads">         
  108.             <?php print $nsoutput; ?>
  109.         </div>
  110. <?php
  111.     }
  112. }
  113. add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_custom_panel_down', 24 );
  114.  
  115. ?>
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement