wc_get_template_part

Get template part (for templates like the shop-loop).

Description

wc_get_template_part( (mixed) $slug, (string) $name = '' ); 

WC_TEMPLATE_DEBUG_MODE will prevent overrides in themes from taking priority.

Parameters (2)

0. $slug (mixed)
The slug.
1. $name — Optional. (string) => ''
(default: '')

Usage

  1. if ( !function_exists( 'wc_get_template_part' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4. // The slug. 
  5. $slug = null; 
  6.  
  7. // (default: '') 
  8. $name = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_get_template_part($slug, $name); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-core-functions.php  
  1. function wc_get_template_part( $slug, $name = '' ) { 
  2. $template = ''; 
  3.  
  4. // Look in yourtheme/slug-name.php and yourtheme/woocommerce/slug-name.php 
  5. if ( $name && ! WC_TEMPLATE_DEBUG_MODE ) { 
  6. $template = locate_template( array( "{$slug}-{$name}.php", WC()->template_path() . "{$slug}-{$name}.php" ) ); 
  7.  
  8. // Get default slug-name.php 
  9. if ( ! $template && $name && file_exists( WC()->plugin_path() . "/templates/{$slug}-{$name}.php" ) ) { 
  10. $template = WC()->plugin_path() . "/templates/{$slug}-{$name}.php"; 
  11.  
  12. // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/woocommerce/slug.php 
  13. if ( ! $template && ! WC_TEMPLATE_DEBUG_MODE ) { 
  14. $template = locate_template( array( "{$slug}.php", WC()->template_path() . "{$slug}.php" ) ); 
  15.  
  16. // Allow 3rd party plugins to filter template file from their plugin. 
  17. $template = apply_filters( 'wc_get_template_part', $template, $slug, $name ); 
  18.  
  19. if ( $template ) { 
  20. load_template( $template, false );