• Resolved wiseupmarketing

    (@wiseupmarketing)


    I have set up a reviews tab using the plugin
    I need to add a code snippet in, to display a review widget
    what is the best approach?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey @wiseupmarketing,

    When you say you need to add a code snippet what type of code are we talking about, php or js?

    Either way I suggest using a filter in your themes functions.php file. You can check to make sure you’re looking at the correct tab and then add the snippet in. If you are trying to add php this will be the most ideal and safe way to do this.

    The following is an example that I pulled from the link that you’ll find at the end of my post. You can create a custom callback function for any tab. In this example we’re targeting the description tab. If you wanted to target a tab that you named “Limited Edition”, you would change this to $tab['limited-edition'] instead. In your callback you can create whatever code snippet you need for your tab.

    Hope this helps!

    Cheers,
    Freddie

    /**
     * Customize product data tabs
     */
    add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
    function woo_custom_description_tab( $tabs ) {
    
    	$tabs['description']['callback'] = 'woo_custom_description_tab_content';	// Custom description callback
    
    	return $tabs;
    }
    
    function woo_custom_description_tab_content() {
    	echo '<h2>Custom Description</h2>';
    	echo '<p>Here\'s a custom description</p>';
    }

    Editing Product Tabs

    Thread Starter wiseupmarketing

    (@wiseupmarketing)

    Would this be a viable implementation

    add_filter( ‘woocommerce_product_tabs’, ‘woo_custom_description_tab’, 98 );
    function woo_custom_description_tab( $tabs ) {

    $tabs[‘Reviews’][‘<div id=”feefo-product-review-widgetId” class=”feefo-review-widget-product” data-feefo-product-id=”{{data-product_id}}”>
    ‘] = ‘woo_custom_description_tab_content’; // Custom description callback

    return $tabs;
    }

    function woo_custom_description_tab_content() {
    echo ‘<h2>Custom Description</h2>’;
    echo ‘<p>Here\’s a custom description</p>’;
    }

    @wiseupmarketing,

    No that wouldn’t work. Here’s the reasons why so that maybe you can get a better idea of what you’re looking at.

    – Reviews should be lowercase because that is targeting the tab name by slug.
    – Where you replaced callback what is that a custom heading? You can add that in a different way you need to keep that box as is with ‘callback’ because that is set in stone and refers to the callback function that will fire for the body of your tab.

    If that html section is something that you’d like to see in your tab body it should look something more like this:

    add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
    function woo_custom_description_tab( $tabs ) {
    
    	$tabs['reviews']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
    
    	return $tabs;
    }
    
    function woo_custom_description_tab_content() {
    	echo '<div id=”feefo-product-review-widgetId” class=”feefo-review-widget-product” data-feefo-product-id=”{{data-product_id}}”></div>';
    }

    Cheers,
    Freddie

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding a code snippet to the tab’ is closed to new replies.