简体   繁体   English

根据用户角色显示自定义主题“my-account.php”woocommerce 页面

[英]Display a custom themed "my-account.php" woocommerce page based on user role

We've been building out a new digital dashboard for my client's upcoming launch of a new digital product, however we wish to only provide access to this newly skinned and structured WooCommerce dashboard (my-account template pages) IF the user has been manually provided a user-role, ie: beta_user, org_manager我们一直在为我的客户即将推出的新数字产品构建一个新的数字仪表板,但是我们希望仅在手动提供用户的情况下提供对这个新皮肤和结构化的 WooCommerce 仪表板(我的帐户模板页面)的访问权限一个用户角色,即:beta_user、org_manager

Any users who do not have this custom role applied would be served the default WooCommerce plugin my-account pages.任何未应用此自定义角色的用户都将获得默认的 WooCommerce 插件我的帐户页面。

Here is what we have tried...这是我们尝试过的...

Added this snippet to the Child Theme functions.php:将此片段添加到子主题 functions.php:

// allow access to new dashboard if user role is org manager 
function isOrgManager(){
    $currentUser = wp_get_current_user();
    return in_array('org_manager', $currentUser->roles);
}

Then applied this to the /child-theme/woocommerce/my-account.php file:然后将此应用于 /child-theme/woocommerce/my-account.php 文件:

<?php if( isOrgManager() ){
        wc_get_template( '/wp-content/themes/blankchildhub/woocommerce/my-account.php' ); 
    } else {        
    wc_get_template( 'myaccount/my-account.php' );
}?>

Any insight would be greatly appreciated as I know this is a fairly common challenge for custom WP and WooCommerce managers.任何见解都将不胜感激,因为我知道这对于自定义 WP 和 WooCommerce 经理来说是一个相当普遍的挑战。

First remove the old file /child-theme/woocommerce/my-account.php首先删除旧文件/child-theme/woocommerce/my-account.php

and then copy /plugins/woocommerce/templates/my-account/my-account.php然后复制/plugins/woocommerce/templates/my-account/my-account.php

to /child-theme/woocommerce/my-account.php/child-theme/woocommerce/my-account.php

then add a switch/ if statement something like below:然后添加一个 switch/if 语句,如下所示:

<?php

/*** filename /child-theme/woocommerce/my-account.php ***/

/**
 * My Account page
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/my-account.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 3.5.0
 */

defined( 'ABSPATH' ) || exit;

/**
 * My Account navigation.
 *
 * @since 2.6.0
 */


// allow access to new dashboard if user role is org manager 
function isOrgManager(){
    $currentUser = wp_get_current_user();
    return in_array('org_manager', $currentUser->roles);
}

<?php

if( isOrgManager() ):

// your custom code....

else:      

do_action( 'woocommerce_account_navigation' ); ?>

<div class="woocommerce-MyAccount-content">
    <?php
        /**
         * My Account content.
         *
         * @since 2.6.0
         */
        do_action( 'woocommerce_account_content' );
    ?>
</div>

<?php

  endif;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 我的帐户页面上,根据特定用户角色显示我的地址部分 - On WooCommerce My account page, display My Addresses section based on specific user role 在 WooCommerce 中添加基于用户角色的自定义我的帐户菜单项 3+ - Add custom my account menu item based on user role in WooCommerce 3+ 在WooCommerce的“我的帐户”仪表板上显示用户角色名称 - Display User Role Name on My Account Dashboard in WooCommerce 仅针对特定用户角色在 Woocommerce 中自定义我的帐户端点 - Custom my account endpoint in Woocommerce just for a specific user role WooCommerce:仅针对特定用户角色显示我的帐户链接 - WooCommerce: Display My Account link only for specific user role 根据用户角色在 WooCommerce 购物车上显示自定义定价标签 - Display Custom Pricing labels on WooCommerce Cart based on user role 如何在woocommerce的帐户详细信息页面中显示自定义用户注册详细信息 - How to Display custom user registration details in Account Details page in woocommerce Woocommerce中根据用户角色自定义客户新账号邮件 - Customize customer new account mail based on user role in Woocommerce 有条件地在woocommerce我的帐户页面上显示一个标签 - Display a Tab on the woocommerce my account page conditionally 根据用户角色更改 Woocommerce 我的帐户选项卡名称 - Change Woocommerce My Account Tab name depending on User Role
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM