相关疑难解决方法(0)

WooCommerce:将自定义模板添加到客户帐户页面

我试图将自定义页面添加到客户的“帐户”部分,这将允许用户编辑其订单。目前,我已经能够设置URL的端点并进行提取,但是我需要让WooCommerce来启动页面布局并能够设置模板位置。

URL被称为:

/my-account/edit-order/55/
Run Code Online (Sandbox Code Playgroud)

这在functions.php文件中,设置了终点并覆盖了模板:

// Working
add_action( 'init', 'add_endpoint' );
function add_endpoint(){
     add_rewrite_endpoint( 'edit-order', EP_ALL );
}

// need something here to check for end point and run page as woocommerce

// Not been able to test
add_filter( 'wc_get_template', 'custom_endpoint', 10, 5 );
function custom_endpoint($located, $template_name, $args, $template_path, $default_path){

    if( $template_name == 'myaccount/my-account.php' ){
        global $wp_query;
        if(isset($wp_query->query['edit-order'])){
            $located = get_template_directory() . '/woocommerce/myaccount/edit-order.php';
        }
    }

    return $located;
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。

php account wordpress endpoint woocommerce

5
推荐指数
1
解决办法
1310
查看次数

标签 统计

account ×1

endpoint ×1

php ×1

woocommerce ×1

wordpress ×1