Asked  1 Year ago    Answers:  5   Viewed   8 times

I am in a deep trouble. Please help me to find a solution for the following.

I have wordpress site which uses Woocommerce Plugin. Normally Woocommerce doesn't allow normal Users (Customer,User - These are roles that you can Select from Wordpress Admin Area > Add new User > Role). The problem is that only Administrator(Role) privilege guys have the access to see the Admin area dashboard and full settings.

I need all users to enter into dashboard area without redirecting to my-account page . Because now when users with Role Customer or something like, tried to enter login credentials of admin, they are getting redirected to my-account page. Only Administrator privilege role has the capability of entering the dashboard and settings.

So I searched in google and found the following link:

WooCommerce admin bar and dashboard access - Role editor page link

I tried the following link by writing the following code in functions.php , but now I can't see admin settings, please see the screenshot that I can see when entering as a normal user.

I need all users access to see admin area dashboard and admin area settings (able to see Post, Page, Settings etc) and donot want to redirect to my-account page.

please help to find a solution for this, since I am struggling with this for a long time.



I spent a lot of time looking for the answer to this one and it can be found in the class-wc-admin.php file under the prevent_admin_access function.

Add the following code:

add_filter( 'woocommerce_prevent_admin_access', '__return_false' );

To your functions PHP file and it will stop it blocking users who do not have: 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' from accessing the dashboard.

For good measure you can also add this which overrides the account permalink to be your admin page - which may be relevant.

function my_account_permalink($permalink) {

    return admin_url();

add_filter( 'woocommerce_get_myaccount_page_permalink', 'my_account_permalink', 1); 
Saturday, May 29, 2021

For anyone having the same problem, I found the solution. Because I have too many products, the page timeout was reached and it stopped loading, without saying so.

The solution is divided in two. First, you need to change the php.ini file and add the following line: memory_limit = 4096M for 4 GB. If you use Cpanel, you can do this directly from WHM interface.

The second step is adding this line to wp-config.php, before including wp-settings.php: define( 'WP_MAX_MEMORY_LIMIT', '256M' );

I hope this helps :)

Thursday, April 1, 2021

This is what I had to add using get_user_meta suggested by LoicTheAztec

function webweb_display_order_data_in_admin( $order ){  ?>
<div class="order_data_column">

        $user_id = $order->get_user_id();
        $key = 'membership_number';
        $single = true;
        $user_membership_number = get_user_meta( $user_id, $key, $single ); 
        echo '<p><strong>' . __( 'Membership Number' ) . ': </strong>' . $user_membership_number . '</p>';
<?php }
add_action( 'woocommerce_admin_order_data_after_order_details', 
'webweb_display_order_data_in_admin' );
Saturday, May 29, 2021

The following hooked function will do the job (You may need to add some CSS style rules):

// Display the product thumbnail in order view pages
add_filter( 'woocommerce_order_item_name', 'display_product_image_in_order_item', 20, 3 );
function display_product_image_in_order_item( $item_name, $item, $is_visible ) {
    // Targeting view order pages only
    if( is_wc_endpoint_url( 'view-order' ) ) {
        $product   = $item->get_product(); // Get the WC_Product object (from order item)
        $thumbnail = $product->get_image(array( 36, 36)); // Get the product thumbnail (from product object)
        if( $product->get_image_id() > 0 )
            $item_name = '<div class="item-thumbnail">' . $thumbnail . '</div>' . $item_name;
    return $item_name;

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Note the WC_Product method get_image() uses Wordpress get_the_post_thumbnail() internally.

Update: added if( $product->get_image_id() > 0 ) to the code, to display the product image, only when it exist.

Saturday, July 31, 2021

Try the following, where you will replace 'some-page' by your real page ID, slug or name. The code will redirect for a defined specific page logged in users to the my account page:

add_action('template_redirect', 'specific_logged_in_redirect');
function specific_logged_in_redirect() {
    if ( is_page('some-page') && is_user_logged_in() ) {
        wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );

Code goes in function.php file of your active child theme (or active theme). Tested and works.

For 2 pages you will use: is_page( array( 'some-page', 'some-other' ) )

Tuesday, October 26, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :