diff --git a/Simple_Custom_Product_Tabs.php b/Simple_Custom_Product_Tabs.php index 02531f7..3d8408b 100644 --- a/Simple_Custom_Product_Tabs.php +++ b/Simple_Custom_Product_Tabs.php @@ -3,7 +3,7 @@ Plugin Name: GWP Custom Product Tabs Plugin URI: Description: A plugin to add Custom product tabs for WooCommerce -Version: 1.1 +Version: 1.2 Author: Ohad Raz Author URI: http://generatewp.com */ @@ -37,7 +37,7 @@ function __construct(){ //save settings tab add_action( 'woocommerce_update_options_'.$this->id, array($this,'update_settings_tab' )); - //add tabs select field + //add tabs select field add_action('woocommerce_admin_field_'.$this->post_type,array($this,'show_'.$this->post_type.'_field' ),10); //save tabs select field add_action( 'woocommerce_update_option_'.$this->post_type,array($this,'save_'.$this->post_type.'_field' ),10); @@ -131,15 +131,13 @@ function show_c_p_tab_field($field){

- ' . esc_html( $tab_name ) . ''; - } + foreach ( $this->get_custom_tabs_list() as $id => $label ) { + $selected = in_array($id, $_ids)? 'selected="selected"' : ''; + echo ''; } ?> @@ -174,22 +172,7 @@ function ajax_footer_js(){ ID, $f['key'], true ); - $_ids = ! empty( $tabs_ids ) ? array_map( 'absint', $tabs_ids ) : null; + $_ids = ! empty( $tabs_ids ) ? array_map( 'absint', $tabs_ids ) : array(); ?>

- ' . esc_html( $tab_name ) . ''; - } + foreach ( $this->get_custom_tabs_list() as $id => $label ) { + $selected = in_array($id, $_ids)? 'selected="selected"' : ''; + echo ''; } ?> @@ -433,5 +414,26 @@ function custom_product_tabs_post_type() { function post_exists($post_id){ return is_string(get_post_status( $post_id ) ); } + + /** + * get_custom_tabs_list + * @since 1.2 + * @return array + */ + function get_custom_tabs_list(){ + $args = array( + 'post_type' => array($this->post_type), + 'post_status' => 'publish', + 'posts_per_page' => -1, + 'fields' => 'ids' + ); + $found_tabs = array(); + $posts = get_posts($args); + if ( $posts ) foreach ( $posts as $post_id ) { + + $found_tabs[ $post_id ] = get_the_title($post_id); + } + return $found_tabs; + } }//end GWP_Custom_Product_Tabs class. new GWP_Custom_Product_Tabs(); \ No newline at end of file