tamerch
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Hi there, i found a solution, but it’s not really a smart one !
ok, so here is what i did :I simply recreate a class named “WoocommerceCustomProductTabsLite2”
with exactly the same functions as the original WoocommerceCustomProductTabsLite.You only have to modify some little things such as using another “product_tabs meta data” name …
here is the code I put at the end of woocommerce-custom-product-tabs-lite.php (NB : I also replaced the text area by TinyMCE Area)
/* Add a tab */ if (!class_exists('WoocommerceCustomProductTabsLite2')) : class WoocommerceCustomProductTabsLite2 { private $tab_data = false; const VERSION = "1.2.0"; public function __construct() {add_action( 'woocommerce_init', array(&$this, 'init2' ));if (is_admin() && !defined('DOING_AJAX')) $this->install();} public function init2() { add_action('woocommerce_product_write_panel_tabs', array($this, 'product_write_panel_tab2')); add_action('woocommerce_product_write_panels', array($this, 'product_write_panel2')); add_action('woocommerce_process_product_meta', array($this, 'product_save_data2'), 10, 2); add_action('woocommerce_product_tabs', array($this, 'custom_product_tabs2'), 25); // in between the attributes and reviews panels add_action('woocommerce_product_tab_panels', array($this, 'custom_product_tabs_panel2'), 25); add_filter( 'woocommerce_custom_product_tabs_lite_content2', 'do_shortcode' ); } public function custom_product_tabs2() { global $product; if($this->product_has_custom_tabs2($product)) { foreach($this->tab_data as $tab) { echo "<li><a href=\"#{$tab['id']}\">".__($tab['title'])."</a></li>"; } } } public function custom_product_tabs_panel2() { global $product; if($this->product_has_custom_tabs2($product)) { foreach($this->tab_data as $tab) { /*add class entry-content*/ echo '<div class="panel entry-content" id="'.$tab['id'].'">'; echo '<h2>' . $tab['title'] . '</h2>'; echo apply_filters( 'woocommerce_custom_product_tabs_lite_content2', $tab['content'], $tab['id'] ); echo '</div>'; } } } private function product_has_custom_tabs2($product) { if($this->tab_data === false) { $this->tab_data = maybe_unserialize( get_post_meta($product->id, 'frs_woo_product_tabs_2', true) ); } // tab must at least have a title to exist return !empty($this->tab_data) && !empty($this->tab_data[0]) && !empty($this->tab_data[0]['title']); } public function product_write_panel_tab2() { echo "<li><a style=\"color:#555555;line-height:16px;padding:9px;text-shadow:0 1px 1px #FFFFFF;\" href=\"#product_tabs2\">".__('Custom Tab 2')."</a></li>"; } public function product_write_panel2() { global $post; // the product $tab_data = maybe_unserialize( get_post_meta($post->ID, 'frs_woo_product_tabs_2', true) ); if(empty($tab_data)) { $tab_data[] = array('title' => '', 'content' => ''); } foreach($tab_data as $tab) { // display the custom tab panel echo '<div id="product_tabs2" class="panel woocommerce_options_panel">'; woocommerce_wp_text_input( array( 'id' => '_tab_title2', 'label' => __('Tab Title 2'), 'description' => __('Required for tab to be visible'), 'value' => $tab['title'] ) ); $this->woocommerce_wp_textarea_input2( array( 'id' => '_tab_content2', 'label' => __('Content 2'), 'placeholder' => __('HTML and text to display2.'), 'value' => $tab['content'], 'style' => 'width:70%;height:21.5em;' ) ); echo '</div>'; } } private function woocommerce_wp_textarea_input2( $field ) { global $thepostid, $post; if (!$thepostid) $thepostid = $post->ID; if (!isset($field['placeholder'])) $field['placeholder'] = ''; if (!isset($field['class'])) $field['class'] = 'short'; if (!isset($field['value'])) $field['value'] = get_post_meta($thepostid, $field['id'], true); echo '<style type="text/css">'; echo '.quicktags-toolbar input {width: auto;}'; echo '#wp-'.$field['id'].'-editor-container {background-color: white;}'; echo '</style>'; echo '<p> Content </p>'; /* TinyMCE */ the_editor( $field['value'],$field['id']); } public function product_save_data2( $post_id, $post ) { $tab_title = stripslashes($_POST['_tab_title2']); $tab_content = stripslashes($_POST['_tab_content2']); if(empty($tab_title) && empty($tab_content) && get_post_meta($post_id, 'frs_woo_product_tabs_2', true)) { // clean up if the custom tabs are removed delete_post_meta($post_id, 'frs_woo_product_tabs_2'); } elseif(!empty($tab_title) || !empty($tab_content)) { $tab_data = array(); $tab_id = ''; if($tab_title) { // convert the tab title into an id string $tab_id = strtolower($tab_title); $tab_id = preg_replace("/[^\w\s]/",'',$tab_id); // remove non-alphas, numbers, underscores or whitespace $tab_id = preg_replace("/_+/", ' ', $tab_id); // replace all underscores with single spaces $tab_id = preg_replace("/\s+/", '-', $tab_id); // replace all multiple spaces with single dashes $tab_id = 'tab-'.$tab_id; // prepend with 'tab-' string } // save the data to the database $tab_data[] = array('title' => $tab_title, 'id' => $tab_id, 'content' => $tab_content); update_post_meta($post_id, 'frs_woo_product_tabs_2', $tab_data); echo $tab_content; } } private function install() { if(get_option('woocommerce_custom_product_tabs_lite_db_version') != WoocommerceCustomProductTabsLite2::VERSION) { $this->upgrade(); // new version number update_option('woocommerce_custom_product_tabs_lite_db_version', WoocommerceCustomProductTabsLite2::VERSION); } } private function upgrade() { global $wpdb; if(!get_option('woocommerce_custom_product_tabs_lite_db_version')) { // this is one of the couple of original users who installed before I had a version option in the db // rename the post meta option 'product_tabs' to 'frs_woo_product_tabs_2' $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_key='frs_woo_product_tabs_2' WHERE meta_key='product_tabs2';"); } } public static function on_activation() { // checks if the woocommerce plugin is running and disables this plugin if it's not (and displays a message) if (!is_plugin_active('woocommerce/woocommerce.php')) { deactivate_plugins(plugin_basename(__FILE__)); wp_die(__('The WooCommerce Product Tabs Lite requires <a href="http://www.woothemes.com/woocommerce/" target="_blank">WooCommerce</a> to be activated in order to work. Please install and activate <a href="http://www.woothemes.com/woocommerce/" target="_blank">WooCommerce</a> first. <a href="'.admin_url('plugins.php').'"> <br> « Go Back</a>')); } // set version number update_option('woocommerce_custom_product_tabs_lite_db_version', WoocommerceCustomProductTabsLite2::VERSION); } } /** * instantiate class */ $woocommerce_product_tabs_lite2 = new WoocommerceCustomProductTabsLite2(); endif; // class exists check /** * run the plugin activation hook */ register_activation_hook(__FILE__, array('WoocommerceCustomProductTabsLite2', 'on_activation'));
Viewing 1 replies (of 1 total)