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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器