wc_get_template() – Get other templates (e.g. product attributes) passing attributes and including the file.

Description

Get other templates (e.g. product attributes) passing attributes and including the file.

Usage

wc_get_template( $template_name, $args, $template_path, $default_path );

Parameters

$template_name
( string ) required – Template name.
$args
( array ) optional – Arguments. (default: array).
$template_path
( string ) optional – Template path. (default: '').
$default_path
( string ) optional – Default path. (default: '').

Returns

void

Source

File name: woocommerce/includes/wc-core-functions.php
Lines:

1 to 53 of 53
function wc_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
  $cache_key = sanitize_key( implode( '-', array( 'template', $template_name, $template_path, $default_path, Constants::get_constant( 'WC_VERSION' ) ) ) );
  $template  = (string) wp_cache_get( $cache_key, 'woocommerce' );

  if ( ! $template ) {
    $template = wc_locate_template( $template_name, $template_path, $default_path );

    // Don't cache the absolute path so that it can be shared between web servers with different paths.
    $cache_path = wc_tokenize_path( $template, wc_get_path_define_tokens() );

    wc_set_template_cache( $cache_key, $cache_path );
  } else {
    // Make sure that the absolute path to the template is resolved.
    $template = wc_untokenize_path( $template, wc_get_path_define_tokens() );
  }

  // Allow 3rd party plugin filter template file from their plugin.
  $filter_template = apply_filters( 'wc_get_template', $template, $template_name, $args, $template_path, $default_path );

  if ( $filter_template !== $template ) {
    if ( ! file_exists( $filter_template ) ) {
      /* translators: %s template */
      wc_doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'woocommerce' ), '<code>' . $filter_template . '</code>' ), '2.1' );
      return;
    }
    $template = $filter_template;
  }

  $action_args = array(
    'template_name' => $template_name,
    'template_path' => $template_path,
    'located'       => $template,
    'args'          => $args,
  );

  if ( ! empty( $args ) && is_array( $args ) ) {
    if ( isset( $args['action_args'] ) ) {
      wc_doing_it_wrong(
        __FUNCTION__,
        __( 'action_args should not be overwritten when calling wc_get_template.', 'woocommerce' ),
        '3.6.0'
      );
      unset( $args['action_args'] );
    }
    extract( $args ); // @codingStandardsIgnoreLine
  }

  do_action( 'woocommerce_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] );

  include $action_args['located'];

  do_action( 'woocommerce_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args'] );
}
 

 View on GitHub View on Trac

Invoked by

    API Letters: ,,