2016-08-08 4 views
2

wc_get_template() 페이지 서식 파일을 반환하지 못하는 것 같습니다. 경로가 내 자식 테마 폴더에 저장되어있는 위치가 맞는지는 확실하지만 실행하면 NULL이됩니다. 여기에 뭐가 잘못 보이니?null을 반환하는 wc_get_template

public function endpoint_content() { 

    // The template name. 
    $template_name = 'Students Details'; 

    // (default: array()) 
    $args = array(); 

    // The template path. 
    $template_path = get_stylesheet_directory().'/woocommerce/myaccount/add_students.php'; 

    // NOTICE! Understand what this does before running. 
    $res = wc_get_template($template_name, $args, $template_path, $template_path); 

    var_dump($res); 
} 
+0

['wc_get_template()'] (https://docs.woocommerce.com/wc-apidocs/source-function-wc_get_template.html#177-206) 함수의 코드를 보면 예상대로 작동하지 않습니다. 아무것도 돌려 보내라. 다른 문서에서는 'returns : void'를 지정합니다. – Henders

+0

어쩌면 [wc_get_template_html()'] (https://github.com/woothemes/woocommerce/blob/master/includes/wc-core-functions.php)에서 '_... wc_get_template'과 비슷하지만 대신 html로 출력하십시오. ' – Henders

+0

@Henders 답장을 보내 주셔서 감사합니다. 그래서 wc_get_template_html() 및 그 반환 된 문자열 (0) ""그래서 궁금 오전 그것은 어쩌면 그것은 자식 테마이기 때문에 노력했다. include 문을 사용하면 잘 작동합니다. 그러나 나는 그 좋은 습관이 있는지 모른다. –

답변

2

당신은 wc_get_template()에 잘못된 인수를 전달하고 있습니다.

  1. $template_name 그렇게 myaccount/student-details.php
  2. $template_path은 빈 문자열 전체 이름입니다. 일반적으로 WC는 테마의 woocommerce 폴더를 볼 것입니다.
  3. $default_path 이것은 플러그인 템플릿의 경로입니다.

    /** 
    * Endpoint HTML content. 
    */ 
    public function endpoint_content() {  
    
        // The template name. 
        $template_name = 'myaccount/student-details.php'; 
    
        // default args 
        $args = array(); 
    
        // default template 
        $template_path = ''; // use default which is usually "woocommerce" 
    
        // default path (look in plugin file!) 
        $default_path = untrailingslashit(plugin_dir_path(__FILE__)) . '/templates/'; 
    
        // call the template 
        wc_get_template($template_name, $args, $template_path, $default_path); 
    
    } 
    

    을 그리고 여기에 샘플 템플릿 wc-your-custom-endpoint-plugin/templates/student-details.php입니다 :

    <?php 
    /** 
    * Template 
    * 
    * @author  Kathy Darling 
    * @package  WC_Custom_Endpoint/Templates 
    * @version  0.1.0 
    */ 
    
    if (! defined('ABSPATH')) exit; // Exit if accessed directly 
    ?> 
    
    <?php do_action('wc_custom_endpoint_before_student_details'); ?> 
    
    <p><?php _e('Hello World!', 'wc-custom-endpoint'); ?><p> 
    
    <?php do_action('wc_custom_endpoint_after_student_details'); ?> 
    
    이 경우 다음 업데이트 된 기능입니다 귀하의 original question

에 내가 당신을 위해 만든 플러그인의 루트 폴더에 templates 폴더를 추가

+0

다시 헬기 워크에 감사드립니다. : D –

+0

@LoicTheAztec 정보를 제공해 주셔서 감사합니다. –