dougu5847 2018-03-20 18: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-20 20: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 51单片机最小开发板系统,想让寻迹小车在全检测到黑线(寻迹模块代码在第一块板子上)时蜂鸣器响(在第二块板子上)
  • ¥15 pbootcms多选调用成列表
  • ¥15 51单片机oled显示时钟
  • ¥15 小规模TSP问题的动态规划求解
  • ¥25 kubelet.service: Failed with result 'exit-code'.
  • ¥15 bitvise黑框内一键部署v2ray提示账户没有root怎么解决
  • ¥15 车型识别以及相似度匹配中细节特征提取以及图像模糊问题
  • ¥15 怎么用鸿蒙的ArkTs写出来啊
  • ¥30 websocket服务端多线程通信
  • ¥15 JNA 方法调用.dll异常
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部