transferring data
-
Hi,
I have two themes and i have setup the first one long time ago. I have published hundreds of products and has added custom tab to all of them using THEME BUILT-IN CUSTOM tab.
but when i install the second theme, it doesnt have the built-in custom tab function.So i have installed your plugin for that.
Now the problem is that how can i transfer all that data from THEME BUILT-IN CUSTOM TAB to you plugin???
Thanks
-
Hi @ahmadtalal0786,
I can’t guarantee this will work but we can try.
We’ll first need to understand how your tab data was saved. Do you have any idea how your old theme was saving custom tab data? Are you able to look at the database to see? Are you able to export your products and tabs?
Also, this kind of work will require some custom code which we can write for you. However, it’d be a huge help if you had some understanding of PHP. Are you familiar with PHP?
Let me know.
Cheers,
Kevin.Hi,
Thanks a lot for replying.
yes i have basic knowledge of PHP.
I have looked into the database but didnt find anything table related to custom tab.
I will attach the old theme Custom Tab PHP code. I cant get around it but may be you can find that from where they ECHO the data.
or may be this code can give you idea it relation with either database or other PHP file.
thnxif ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly
/**
* Filter tabs and allow third parties to add their own
*
* Each tab is an array containing title, callback and priority.
* @see woocommerce_default_product_tabs()
*/
$tabs = apply_filters( ‘woocommerce_product_tabs’, array() );
if(!empty($tabs[‘additional_information’])) {
$tabs[‘additional_information’][‘title’] = __(‘Product Details’, ‘legenda’);
}
?>
<div class=”tabs <?php etheme_option(‘tabs_type’); ?>”>
<?php if ( ! empty( $tabs ) ) : ?>
<?php foreach ( $tabs as $key => $tab ) : ?>
” id=”tab_<?php echo $key ?>” class=”tab-title”><?php echo apply_filters( ‘woocommerce_product_’ . $key . ‘_tab_title’, $tab[‘title’], $key ) ?>
<div class=”tab-content” id=”content_tab_<?php echo $key ?>”>
<?php call_user_func( $tab[‘callback’], $key, $tab ) ?>
</div>
<?php endforeach; ?>
<?php endif; ?><?php if (etheme_get_custom_field(‘custom_tab1_title’) && etheme_get_custom_field(‘custom_tab1_title’) != ” ) : ?>
<?php etheme_custom_field(‘custom_tab1_title’); ?>
<div id=”content_tab_7″ class=”tab-content”>
<?php echo do_shortcode(etheme_get_custom_field(‘custom_tab1’)); ?>
</div>
<?php endif; ?><?php if (etheme_get_option(‘custom_tab_title’) && etheme_get_option(‘custom_tab_title’) != ” ) : ?>
<?php etheme_option(‘custom_tab_title’); ?>
<div id=”content_tab_9″ class=”tab-content”>
<?php echo do_shortcode(etheme_get_option(‘custom_tab’)); ?>
</div>
<?php endif; ?>
</div>These are the main customizations I see happening:
– For your Additional Information tab (one of WooCommerce’s default tabs), the title is being changed to “Product Details.” This is not something our plugin has control over because we don’t deal with default tabs but I think you’ll be able to keep this.
– There is then 2 additional hardcoded custom tabs that – I believe – are stored in your wp_options table. They are being pulled with the function
etheme_get_custom_field
andetheme_get_option
with the keyscustom_tab1_title
,custom_tab1
,custom_tab_title
andcustom_tab
. Can you search your options table (either key or value) for these names?Thank you,
Kevin.Hello,
Thank you soooooooooooooo much for replying,
I have asked my old theme developer and she said that the data is in wp_postmeta table,
So can you please write me some custom php to echo the data,
Thanks a lot,
I really appreciate your help
??????Hi @ahmadtalal0786,
Do you have access to your database. Can you run a query like
SELECT * FROM wp_postmeta WHERE meta_key = 'custom_tab1_title
OR meta_key = ‘custom_tab_title’` and confirm that the tab data is stored with those keys?Let me know.
Thank you,
Kevin.Hi,
Thanks a lot for replying.
Yes i have ran the query at sql and I have found the result of ‘custom_tab1_title’
All the data is present in the same table under that name.Thank you for helping me out. appreciate it
Okay sounds good thank you for doing that.
One more question: how many products do you have?
I want to run a query that fetches all of your products and loops through them. However, WordPress can have issues when trying to fetch more than ~2000 products at a time. I am trying to avoid that issue.
Let me know.
Cheers,
Kevin.Thnx for the quick reply.
Right now i have around 260 products. so the number of products wont be an issue.Alright. Let’s give this a try. Can you give me the ID of a single product so we can test our process with that product? (Hopefully a product that already has two custom tabs).
Here is the full snippet but please don’t run this now.
add_action( 'admin_init', 'convert_tab_manager_to_custom_product_tabs' ); function convert_tab_manager_to_custom_product_tabs() { if ( ! isset( $_GET['yikes'] ) ) { return; } // Get 500 of our products that have the <code>_product_tabs</code> post meta field $wp_query_args = array( 'post_type' => 'product', // 'posts_per_page' => '500', // 'paged' => $_GET['yikes'], 'post_status' => 'publish', 'meta_query' => array( 'compare' => 'OR', array( 'key' => 'custom_tab', 'value' => 'product', 'compare' => 'EXISTS' ), array( 'key' => 'custom_tab1', 'value' => 'product', 'compare' => 'EXISTS' ) ) ); $products = new WP_Query( $wp_query_args ); // Make sure we have products if ( $products->have_posts() ) { global $post; // Go through each product while ( $products->have_posts() ) { $products->the_post(); // Get the array of Tabs Manager tabs $old_tab1_content = get_post_meta( get_the_ID(), 'custom_tab', true ); $old_tab1_title = get_post_meta( get_the_ID(), 'custom_tab_title', true ); $old_tab2_content = get_post_meta( get_the_ID(), 'custom_tab1', true ); $old_tab2_title = get_post_meta( get_the_ID(), 'custom_tab1_title', true ); // If we don't have tab data, go to the next product. if ( empty( $old_tab1_content ) && empty( $old_tab1_title ) && empty( $old_tab2_content ) && empty( $old_tab2_title ) ) { continue; } // Get the array of YIKES Custom Product Tabs data $new_tab_data = get_post_meta( get_the_ID(), 'yikes_woo_products_tabs', true ); // Make sure we're dealing with an array $new_tab_data = is_array( $new_tab_data ) ? $new_tab_data : array(); // Make sure tab 1 isn't empty if ( ! empty( $old_tab1_content ) && ! empty( $old_tab1_title ) ) { // Create the new tab structure for Custom Product Tabs - Tab 1 $new_tab_data[] = array( 'id' => sanitize_title( $old_tab1_title ), // Slug 'title' => $old_tab1_title, // Title 'content' => $old_tab1_content // Content ); } if ( ! empty( $old_tab2_content ) && ! empty( $old_tab2_title ) ) { // Create the new tab structure for Custom Product Tabs - Tab 2 $new_tab_data[] = array( 'id' => sanitize_title( $old_tab2_title ), // Slug 'title' => $old_tab2_title, // Title 'content' => $old_tab2_content // Content ); } if ( ! empty( $new_tab_data ) ) { // Save the new tab data update_post_meta( get_the_ID(), 'yikes_woo_products_tabs', $new_tab_data ); } } } }
Cheers,
Kevin.Hi,
Thanks a lot.
Here is the ID for one of the product i have.
ID = 1927
I hope it will workOkay cool. And you have Custom Product Tabs installed & activated and you’re able to create tabs right? (Making sure the plugin works with your theme’s customizations).
The first thing to do is to remove these lines from the file you pasted earlier:
<?php if (etheme_get_custom_field('custom_tab1_title') && etheme_get_custom_field('custom_tab1_title') != '' ) : ?> <?php etheme_custom_field('custom_tab1_title'); ?> <div id="content_tab_7" class="tab-content"> <?php echo do_shortcode(etheme_get_custom_field('custom_tab1')); ?> </div> <?php endif; ?> <?php if (etheme_get_option('custom_tab_title') && etheme_get_option('custom_tab_title') != '' ) : ?> <?php etheme_option('custom_tab_title'); ?> <div id="content_tab_9" class="tab-content"> <?php echo do_shortcode(etheme_get_option('custom_tab')); ?> </div> <?php endif; ?> </div>
That should prevent your theme from using it’s tabs.
Then add this code to your functions.php file:
add_action( 'admin_init', 'convert_tab_manager_to_custom_product_tabs' ); function convert_tab_manager_to_custom_product_tabs() { if ( ! isset( $_GET['yikes'] ) ) { return; } // Get our products that have the <code>custom_tab</code> or <code>custom_tab1</code> post meta field $wp_query_args = array( 'post_type' => 'product', 'post__in' => array( 1927 ), 'post_status' => 'publish', 'meta_query' => array( 'compare' => 'OR', array( 'key' => 'custom_tab', 'value' => 'product', 'compare' => 'EXISTS' ), array( 'key' => 'custom_tab1', 'value' => 'product', 'compare' => 'EXISTS' ) ) ); $products = new WP_Query( $wp_query_args ); // Make sure we have products if ( $products->have_posts() ) { global $post; // Go through each product while ( $products->have_posts() ) { $products->the_post(); // Get the old tabs $old_tab1_content = get_post_meta( get_the_ID(), 'custom_tab', true ); $old_tab1_title = get_post_meta( get_the_ID(), 'custom_tab_title', true ); $old_tab2_content = get_post_meta( get_the_ID(), 'custom_tab1', true ); $old_tab2_title = get_post_meta( get_the_ID(), 'custom_tab1_title', true ); // If we don't have tab data, go to the next product. if ( empty( $old_tab1_content ) && empty( $old_tab1_title ) && empty( $old_tab2_content ) && empty( $old_tab2_title ) ) { continue; } // Get the array of YIKES Custom Product Tabs data $new_tab_data = get_post_meta( get_the_ID(), 'yikes_woo_products_tabs', true ); // Make sure we're dealing with an array $new_tab_data = is_array( $new_tab_data ) ? $new_tab_data : array(); // Make sure tab 1 isn't empty if ( ! empty( $old_tab1_content ) && ! empty( $old_tab1_title ) ) { // Create the new tab structure for Custom Product Tabs - Tab 1 $new_tab_data[] = array( 'id' => sanitize_title( $old_tab1_title ), // Slug 'title' => $old_tab1_title, // Title 'content' => $old_tab1_content // Content ); } // Make sure tab 2 isn't empty if ( ! empty( $old_tab2_content ) && ! empty( $old_tab2_title ) ) { // Create the new tab structure for Custom Product Tabs - Tab 2 $new_tab_data[] = array( 'id' => sanitize_title( $old_tab2_title ), // Slug 'title' => $old_tab2_title, // Title 'content' => $old_tab2_content // Content ); } if ( ! empty( $new_tab_data ) ) { // Save the new tab data update_post_meta( get_the_ID(), 'yikes_woo_products_tabs', $new_tab_data ); } } } }
Then, to execute the code, go to your dashboard (e.g. https://www.example.com/wp-admin) and add the variable
?yikes=yikes
to the URL (e.g.www.example.com/wp-admin?yikes=yikes
)Only run it once! Then go to your 1927 product and check it out.
hi,
Do i need to create custom tab with yikes or no before to run the code-
This reply was modified 6 years, 10 months ago by
ahmadtalal0786.
You don’t need to create any custom tabs for the script but it would be helpful for you to make one for a product just to make sure it’s working with your theme. You can go to a product, add a custom tab, save it, make sure it’s displaying on the front-end, and then delete the tab. If that’s working, feel free to run the script.
Hello,
When i created a new tab using your plugin and tested then it worked.
after that i have copied the php to function.php file and run the yikes query in the url. when i checked. it didnt work.Also the php code i have sent for the custom tab was from the old theme. I have check the same woocommerce > single product > tab folder, I have found three php files.
PHP of file one called accordian:
$tabs = apply_filters( ‘woocommerce_product_tabs’, array() );if ( ! empty( $tabs ) ) : ?>
<div class=”product-page-accordian”>
<div class=”accordion” rel=”1″>
<?php foreach ( $tabs as $key => $tab ) : ?>
<div class=”accordion-item”>
<button class=”toggle”><i class=”icon-angle-down”></i></button>
<?php echo apply_filters( ‘woocommerce_product_’ . $key . ‘_tab_title’, $tab[‘title’], $key ) ?>
<div class=”accordion-inner”>
<?php call_user_func( $tab[‘callback’], $key, $tab ) ?>
</div>
</div><!– accordion-item –>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>PHP of file two called Section:
$tabs = apply_filters( ‘woocommerce_product_tabs’, array() );if ( ! empty( $tabs ) ) : ?>
<div class=”product-page-sections”>
<?php foreach ( $tabs as $key => $tab ) : ?>
<div class=”product-section”>
<div class=”row”>
<div class=”large-2 col pb-0 mb-0″>
<h5 class=”uppercase mt”><?php echo apply_filters( ‘woocommerce_product_’ . $key . ‘_tab_title’, $tab[‘title’], $key ) ?></h5>
</div><div class=”large-10 col pb-0 mb-0″>
<div class=”panel entry-content”>
<?php call_user_func( $tab[‘callback’], $key, $tab ) ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>PHP of file three called tabs:
if ( ! defined( ‘ABSPATH’ ) ) {
exit; // Exit if accessed directly
}// Get sections instead of tabs if set
if(get_theme_mod(‘product_display’) == ‘sections’){
wc_get_template_part( ‘single-product/tabs/sections’ );
return;
}// Get accordian instead of tabs if set
if(get_theme_mod(‘product_display’) == ‘accordian’){
wc_get_template_part( ‘single-product/tabs/accordian’ );
return;
}/**
* Filter tabs and allow third parties to add their own
*
* Each tab is an array containing title, callback and priority.
* @see woocommerce_default_product_tabs()
*/
$tabs = apply_filters( ‘woocommerce_product_tabs’, array() );
$count_tabs = 0;
$count_panel = 0;if ( ! empty( $tabs ) ) : ?>
<div class=”woocommerce-tabs container tabbed-content”>
<ul class=”product-tabs nav small-nav-collapse tabs <?php flatsome_product_tabs_classes() ?>”>
<?php
foreach ( $tabs as $key => $tab ) : ?>
<li class=”<?php echo esc_attr( $key ); ?>_tab <?php if($count_tabs == 0) echo ‘active’;?>”>
“><?php echo apply_filters( ‘woocommerce_product_’ . $key . ‘_tab_title’, esc_html( $tab[‘title’] ), $key ); ?><?php $count_tabs++; endforeach; ?>
<div class=”tab-panels”>
<?php foreach ( $tabs as $key => $tab ) : ?><div class=”panel entry-content <?php if($count_panel == 0) echo ‘active’;?>” id=”tab-<?php echo $key ?>”>
<?php if($key == ‘description’ && ux_builder_is_active()) { echo flatsome_dummy_text(); } ?>
<?php call_user_func( $tab[‘callback’], $key, $tab ) ?>
</div><?php $count_panel++; endforeach; ?>
</div><!– .tab-panels –>
</div><!– .tabbed-content –><?php endif; ?>
do i need to remove some code from these?
Agh I forgot you weren’t using that theme anymore. You don’t need to remove any of the code from those files.
There are no tabs for Product 1927? If you run these queries in the DB do you see old or new tabs?
Old tabs:
SELECT * FROM wp_postmeta WHERE meta_key = 'custom_tab' AND post_id = 1927
New tabs:
SELECT * FROM wp_postmeta WHERE meta_key = 'yikes_woo_products_tabs' AND post_id = 1927
-
This reply was modified 6 years, 10 months ago by
- The topic ‘transferring data’ is closed to new replies.