Support of the Custom Product Tabs for WooCommerce (YIKES, Inc.)

To make the theme compatible with the Custom Product Tabs for WooCommerce plugin add the following code in child theme functions.php file:

add_filter('etheme_single_product_builder_tabs', 'etheme_single_product_builder_tabs_yikes_custom');

function etheme_single_product_builder_tabs_yikes_custom($tabs) {
    if (!class_exists('YIKES_Custom_Product_Tabs_Display')) {
        return $tabs;
    }
    global $product;

    $product_id = method_exists( $product, 'get_id' ) === true ? $product->get_id() : $product->ID;

    $product_tabs = maybe_unserialize( get_post_meta( $product_id, 'yikes_woo_products_tabs' , true ) );

    if ( ! empty( $product_tabs ) ) {

        // Setup priorty to loop over, and render tabs in proper order
        $i = 60; 

        foreach ( $product_tabs as $tab ) {

            // Do not show tabs with empty titles on the front end
            if ( empty( $tab['title'] ) ) {
                continue;
            }

            $tab_key = $tab['id']; 

            $tabs[ $tab_key ] = array(
                'title'     => $tab['title'],
                'priority'  => $i++,
                'callback'  => 'custom_product_tabs_panel_content_yikes',
                'content'   => $tab['content']
            );
        }
    }

    /**
    * Filter: 'yikes_woo_filter_all_product_tabs'
    *
    * Generic filter that passes all of the tab info and the corresponding product. Cheers.
    *
    * Note: This passes all of the tabs for the current product, not just the Custom Product Tabs created by this plugin.
    *
    * @param array  | $tab      | Array of $tab data arrays.
    * @param object | $product  | The WooCommerce product these tabs are for
    */
    $tabs = apply_filters( 'yikes_woo_filter_all_product_tabs', $tabs, $product );

    return $tabs;
}

function custom_product_tabs_panel_content_yikes( $key, $tab ) {

    $content = '';          

    $use_the_content_filter = apply_filters( 'yikes_woo_use_the_content_filter', true );

    if ( $use_the_content_filter === true ) {
        $content = apply_filters( 'the_content', $tab['content'] );
    } else {
        $content = apply_filters( 'yikes_woo_filter_main_tab_content', $tab['content'] );
    }

    $tab_title_html = '<h2 class="yikes-custom-woo-tab-title yikes-custom-woo-tab-title-' . urldecode( sanitize_title( $tab['title'] ) ) . '">' . $tab['title'] . '</h2>';
    echo apply_filters( 'yikes_woocommerce_custom_repeatable_product_tabs_heading', $tab_title_html, $tab );
    echo apply_filters( 'yikes_woocommerce_custom_repeatable_product_tabs_content', $content, $tab );
}
Updated on September 26, 2024
Was this Article helpful?