Advertisement
bmex63

WooCommerce 2.0 Custom Product Tab for WP Download Monitor

Mar 25th, 2013
1,894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * Custom Tabs for Downloads Display from Download Monitor Plugin by Mike Jolley. Compatible with WooCommerce 2.0+ only!
  5.  *
  6.  * Outputs an extra tab to the default set of info tabs on the single product page.
  7.  * This file needs to be called via your functions.php file.
  8.  
  9.  */
  10. function custom_tab_options_tab_down() {
  11. ?>
  12.     <li class="custom_tab2"><a href="#custom_tab_data2"><?php _e('Custom Tab 2', 'woothemes'); ?></a></li>
  13. <?php
  14. }
  15. add_action('woocommerce_product_write_panel_tabs', 'custom_tab_options_tab_down');
  16.  
  17.  
  18. /**
  19.  * Custom Tab Options
  20.  *
  21.  * Provides the input fields and add/remove buttons for custom tabs on the single product page.
  22.  */
  23. function custom_tab_options_down() {
  24.     global $post;
  25.    
  26.     $custom_tab_options_down = array(
  27.         'titleb' => get_post_meta($post->ID, 'custom_tab_title_down', true),
  28.         'contentb' => get_post_meta($post->ID, 'custom_tab_content_down', true),
  29.     );
  30.    
  31. ?>
  32.     <div id="custom_tab_data2" class="panel woocommerce_options_panel">
  33.         <div class="options_group">
  34.             <p class="form-field">
  35.                 <?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') ) ); ?>
  36.             </p>
  37.         </div>
  38.        
  39.         <div class="options_group custom_tab_options">                                             
  40.             <p class="form-field">
  41.                 <label><?php _e('Custom Tab Title:', 'woothemes'); ?></label>
  42.                 <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'); ?>" />
  43.             </p>
  44.            
  45.             <p class="form-field">
  46.                 <?php _e('Custom Tab Content:', 'woothemes'); ?>
  47.             </p>
  48.            
  49.             <table class="form-table">
  50.                 <tr>
  51.                     <td>
  52.                         <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>
  53.                     </td>
  54.                 </tr>  
  55.             </table>
  56.         </div> 
  57.     </div>
  58. <?php
  59. }
  60. add_action('woocommerce_product_write_panels', 'custom_tab_options_down');
  61.  
  62.  
  63. /**
  64.  * Process meta
  65.  *
  66.  * Processes the custom tab options when a post is saved
  67.  */
  68. function process_product_meta_custom_tab_down( $post_id ) {
  69.     update_post_meta( $post_id, 'custom_tab_enabled_down', ( isset($_POST['custom_tab_enabled_down']) && $_POST['custom_tab_enabled_down'] ) ? 'yes' : 'no' );
  70.     update_post_meta( $post_id, 'custom_tab_title_down', $_POST['custom_tab_title_down']);
  71.     update_post_meta( $post_id, 'custom_tab_content_down', $_POST['custom_tab_content_down']);
  72. }
  73. add_action('woocommerce_process_product_meta', 'process_product_meta_custom_tab_down', 10, 2);
  74.  
  75.  
  76. /**
  77.  * Display Tab
  78.  *
  79.  * Display Custom Tab on Frontend of Website for WooCommerce 2.0
  80.  */
  81.  
  82. add_filter( 'woocommerce_product_tabs', 'woocommerce_product_custom_tab_down' );
  83.  
  84.  
  85.     function woocommerce_product_custom_tab_down( $tabs ) {
  86.         global $post, $product;
  87.  
  88.         $custom_tab_options_down = array(
  89.             'enabled' => get_post_meta($post->ID, 'custom_tab_enabled_down', true),
  90.             'titleb' => get_post_meta($post->ID, 'custom_tab_title_down', true),
  91.             'contentb' => get_post_meta($post->ID, 'custom_tab_content_down', true),           
  92.         );
  93.                
  94.        
  95.             if ( $custom_tab_options_down['enabled'] != 'no' ){
  96.                 $tabs['custom-tab-third'] = array(
  97.                     'title'    => $custom_tab_options_down['titleb'],
  98.                     'id' => 'test_multicheckbox',  
  99.                     'priority' => 35,
  100.                     'callback' => 'custom_product_tabs_panel_content_down',                
  101.                     'content'  => $custom_tab_options_down['contentb']
  102.                 );
  103.             }
  104.  
  105.         return $tabs;
  106.     }
  107.  
  108.     /**
  109.      * Render the custom product tab panel content for the callback 'custom_product_tabs_panel_content_down'
  110.      */
  111.    function custom_product_tabs_panel_content_down( $key, $custom_tab_options_down ) {
  112.         global $post, $product;
  113.    
  114.         $custom_tab_options_down = array(
  115.             'enabled' => get_post_meta($post->ID, 'custom_tab_enabled_down', true),
  116.             'titleb' => get_post_meta($post->ID, 'custom_tab_title_down', true),
  117.             'contentb' => get_post_meta($post->ID, 'custom_tab_content_down', true),           
  118.         );
  119.        
  120.         $downloads = get_post_meta($post->ID, 'custom_tab_content_down', true);
  121.         $nsoutput = do_shortcode( $downloads ) ;       
  122.            
  123.         echo '<h2>' . $custom_tab_options_down['titleb'] . '</h2>';
  124.         print $nsoutput;
  125.     }
  126.  
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement