Advertisement
daymobrew

WooCommerce Tabs as details disclosure element

Apr 12th, 2024
522
0
9 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | Source Code | 0 0
  1. <?php
  2. /**
  3.  * Single Product tabs
  4.  *
  5.  * This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/tabs.php.
  6.  *
  7.  * HOWEVER, on occasion WooCommerce will need to update template files and you
  8.  * (the theme developer) will need to copy the new files to your theme to
  9.  * maintain compatibility. We try to do this as little as possible, but it does
  10.  * happen. When this occurs the version of the template file will be bumped and
  11.  * the readme will list any important changes.
  12.  *
  13.  * @see     https://woo.com/document/template-structure/
  14.  * @package WooCommerce\Templates
  15.  * @version 3.8.0
  16.  */
  17.  
  18. // Change tabs from ul/li and div to details/summary disclosure element.
  19.  
  20. if ( ! defined( 'ABSPATH' ) ) {
  21.     exit;
  22. }
  23.  
  24. /**
  25.  * Filter tabs and allow third parties to add their own.
  26.  *
  27.  * Each tab is an array containing title, callback and priority.
  28.  *
  29.  * @see woocommerce_default_product_tabs()
  30.  */
  31. $product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
  32.  
  33. if ( ! empty( $product_tabs ) ) : ?>
  34.  
  35.     <div class="woocommerce-tabs wc-tabs-wrapper">
  36.             <?php foreach ( $product_tabs as $key => $product_tab ) : ?>
  37.                 <details class="<?php echo esc_attr( $key ); ?>_tab" id="tab-title-<?php echo esc_attr( $key ); ?>" role="tab" aria-controls="tab-<?php echo esc_attr( $key ); ?>">
  38.                     <summary><?php echo wp_kses_post( apply_filters( 'woocommerce_product_' . $key . '_tab_title', $product_tab['title'], $key ) ); ?></summary>
  39.                     <?php
  40.                     if ( isset( $product_tab['callback'] ) ) {
  41.                         call_user_func( $product_tab['callback'], $key, $product_tab );
  42.                     }
  43.                     ?>
  44.                 </details>
  45.             <?php endforeach; ?>
  46.  
  47.         <?php do_action( 'woocommerce_product_after_tabs' ); ?>
  48.     </div>
  49.  
  50. <?php endif; ?>
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement