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.

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。