• We have a few tabs using the free version of this plugin that we sometimes want to pull the content for use in another page of the website without needing to remember everywhere we placed that products info.

    Is it possible to pull the data from our custom tabs using a short code?

    Thank you in advance.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi @binarywc,

    You can use shortcodes in the content of your tabs, so my recommendation would be to define a shortcode separately and use it in your tab’s content and any other needed location.

    You could also theoretically write a shortcode to pull specific tab data from your products, but you would need to know the product’s ID and the title of tab at minimum. Then you could use a strategy like this:

    
    $tabs = get_post_meta($product_id, 'yikes_woo_products_tabs', true);
    
    $tab = array_filter($tabs, function($tab){
      return 'my-title' === $tab['title'];
    });
    

    to fetch the tab data for that product in the body of a shortcode function.

    Option one would be much easier unless you have a specific reason for needing the tab defined on the product.

    Let me know if that helps,
    Jon

    • This reply was modified 3 years, 6 months ago by jpowersdev.
    • This reply was modified 3 years, 6 months ago by jpowersdev.
    Thread Starter Davood Denavi

    (@binarywc)

    Option one would not work because there are 40+ products that all have different content in the description and custom tabs we’ve added and we want to put the info in the woocommerce database directly so it is easy to update it.

    I will try the second option later today and reply again if I need more assistance but I think that will not do precisely what I am looking for based on what I used to create a short code for the default description tab.

    Thread Starter Davood Denavi

    (@binarywc)

    Hi, Does the second method you suggested require that the tabs are universal tabs that are added in the “Saved Tabs” screen?

    Please let me know.

    Thread Starter Davood Denavi

    (@binarywc)

    @jpowersdev Did you see my question from a few days ago?

    Hi @binarywc,

    Sorry, I was out last week.

    No, it does not require that they are universal tabs. Did you run into issues?

    Jon

    Thread Starter Davood Denavi

    (@binarywc)

    I would not necessarily say I ran into issues except that the code was not working when I created the short it was returning nothing from the tab we were using. I will play around with it a bit more and update you with my exact code in the next couple days. Thanks for your reply to my question.

    Hi @binarywc,

    Just checking in, are you still having trouble or were you able to figure it out?

    Jon

    Thread Starter Davood Denavi

    (@binarywc)

    Nope. When I created the shortcode it was not returning the content at all. I have still been digging for a solution but haven’t come up with one yet.

    Thread Starter Davood Denavi

    (@binarywc)

    @jpowersdev I believe the problems I’m running into relate to my shortcode also needing the product id… The problem with this is I’m not farm iOS familiar with the code from your plugin so I’m not sure if I’d need a different hook or filter than the default ones offered by Woocommerce. Would you mind clarifying that for me? Thank you in advance in advance!

    Hi @binarywc,

    Could you post the full code snippet here so I can take a look?

    Thanks,
    Jon

    Thread Starter Davood Denavi

    (@binarywc)

    @jpowersdev I have tried too many code snippets to count with no luck! None of the snippets returned and content when I used the short code. Like I said in my last post i think the product id is needed and I’m not familiar with the code from your plugin so I’m not sure if I’d need a different hook or filter than the default ones offered by Woocommerce!

    Hi @binarywc,

    In the case of the product ID – Since this shortcode is only running in tabs on a single product page, get_the_ID() should return the ID of the current product. That’s a core WordPress function you can use here because we’re in The Loop.

    Once you grab the meta value for the tabs (using the product ID), you can use something like print_r or var_dump to see the shape of that data so you can determine what you need. My little array_filter snippet is looping through the list of tabs and picking out the one with a matching title. That way you can check to see if it exists.

    Let me know if that helps,
    Jon

    Thread Starter Davood Denavi

    (@binarywc)

    @jpowersdev No, that does not really help because I have not had time to familiarize my self with the code in the Custom Product Tabs for WooCommerce plugin and the problem is that what you told me to use for the short code is returning literally nothing, not even an error… no matter what I’ve done in my 12-15 tests.

    However, I realized that I was saying

    I’m not sure if I’d need a different hook or filter than the default ones offered by Woocommerce!

    I really mean I’m not sure if I’d need a different hook or filter than the default ones offered by WordPress!

    Would you please provide me a sample short code function based on your plugin that will return the content/copy of one single tab. I will then be able to understand what I misunderstood from your post a few weeks ago.

    Thank you in advance.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Shortcode for tabs’ is closed to new replies.