dougu5847
2018-03-21 02:53
浏览 166
已采纳

在Woocommerce我的帐户页面中包含自定义模板文件问题

I am trying to add an include a template file located in my active child theme:

childtheme/woocommerce/myaccount/order-a-kit.php

The function use also echo "Hello World" which is displayed successfully, but not the included php template file.

I have tried those:

include($_SERVER['DOCUMENT_ROOT']."twentyseventeen-child/woocommerce/myaccount/order-a-kit.php");

include($get_stylesheet_directory_uri()."twentyseventeen-child/woocommerce/myaccount/order-a-kit.php");

include 'twentyseventeen-child/woocommerce/myaccount/order-a-kit.php';

The content of the order-a-kit.php is super simple, I am just trying to include that file:

<?php
?>

<div>
    <p>
        Look at me
    </p>
</div>

This is my function.php section and everything is doing as it should except the include function towards the bottom:

add_filter( 'woocommerce_account_menu_items', 'add_my_menu_items', 99, 1 );

function add_my_menu_items( $items ) {
    $my_items = array(
    //  endpoint   => label
        'order-a-kit' => __( 'Order A Kit', 'woocommerce'),
        'orders' => __( 'Order History', 'my_plugin' ),
    );

    $my_items = array_slice( $items, 0, 1, true ) +
        $my_items +
        array_slice( $items, 1, count( $items ), true );

    return $my_items;
}


//adding custom endpoint 

function my_custom_endpoints() {
    add_rewrite_endpoint( 'order-a-kit', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'my_custom_endpoints' );

function my_custom_query_vars( $vars ) {
    $vars[] = 'order-a-kit';

    return $vars;
}

add_filter( 'query_vars', 'my_custom_query_vars', 0 );

function my_custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}

add_action( 'wp_loaded', 'my_custom_flush_rewrite_rules' );

//including custom endpoint

function my_custom_endpoint_content() {
    include 'twentyseventeen-child/woocommerce/myaccount/order-a-kit.php';
    echo '<p>Hello World!</p>';
}

add_action( 'woocommerce_account_order-a-kit_endpoint', 'my_custom_endpoint_content' );


?>

Any help is greatly appreciated.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试添加一个包含位于我的活动子主题中的模板文件: \ n

childtheme / woocommerce / myaccount / order-a-kit.php

该函数还使用 echo“Hello World”显示成功,但没有包含的php模板文件。

我尝试过这些:

  include($ _ SERVER ['  。DOCUMENT_ROOT'] “twentyseventeen独生子女/ woocommerce /我的帐户/订单-A-kit.php”); 
 
include($ get_stylesheet_directory_uri() “twentyseventeen独生子女/ woocommerce /我的帐户/订单-A-kit.php”  ); 
 
include'levenseventeen-woocommerce / myaccount / order-a-kit.php'; 
   
 
 

命令的内容 - a-kit.php 非常简单,我只想尝试包含该文件:

 &lt;?php 
?&gt; 
 
&lt;  div&gt; 
&lt; p&gt; 
看看我
&lt; / p&gt; 
&lt; / div&gt; 
   
 
 

这是我的函数 .php 部分,一切都如此 它应该除了底部的include函数之外:

  add_filter('woocommerce_account_menu_items','add_my_menu_items',99,1); 
 
function add_my_menu_items($ items){\  n $ my_items = array(
 // endpoint =&gt;  label 
'order-a-kit'=&gt;  __('订购套件','woocommerce'),
'orders'=&gt;  __('订单历史','my_plugin'),
); 
 
 $ my_items = array_slice($ items,0,1,true)+ 
 $ my_items + 
 array_slice($ items,1,count  ($ items),true); 
 
返回$ my_items; 
} 
 
 
 //添加自定义端点
 
function my_custom_endpoints(){
 add_rewrite_endpoint('order-a-kit',  EP_ROOT | EP_PAGES); 
} 
 
add_action('init','my_custom_endpoints'); 
 
function my_custom_query_vars($ vars){
 $ vars [] ='order-a-kit'; 
 \  n返回$ vars; 
} 
 
add_filter('query_vars','my_custom_query_vars',0); 
 
function my_custom_flush_rewrite_rules(){
 flush_rewrite_rules(); 
} 
 
add_action('wp_loaded',  'my_custom_flush_rewrite_rules'); 
 
 //包括自定义端点
 
function my_custom_endpoint_content(){
包括'twentyseventeen-child / woocommerce / myaccount / order-a-kit.php'; 
 echo'&lt; p&gt;  ; Hello World!&lt; / p&gt;'; 
} 
 
add_action('woocommerce_account_order-a-kit_endpoint','my_custom_endpoint_content'); 
 
 
?&gt; 
   
  
 

非常感谢任何帮助。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • doubiankang2845 2018-03-21 04:19
    最佳回答

    As the "woocommerce" folder is inside your theme as the function.php file you just need to use:

    include 'woocommerce/myaccount/order-a-kit.php';
    

    See this related answer: WooCommerce: Adding custom template to customer account pages

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题