trogdoor84
trogdoor84

Reputation: 45

Remove ‘Customer payment page’ restrictions for admins in WooCommerce (pay_for_order capability?)

I’m interested in removing the restriction which prevents anyone other than the customer paying for their order, so that an admin can step in and do the payment on behalf of the customer for when customers have trouble making the payment themselves for any reason.

Currently if a customer makes an order and fails the payment, the link to ‘Customer payment page’ from the order edit screen takes you to a message that says:

This order cannot be paid for. Please contact us if you need assistance.

This is the restriction I’m trying to remove – I’ve narrowed it down to this code;

// Logged in customer trying to pay for someone else's order.
            if ( ! current_user_can( 'pay_for_order', $order_id ) ) {
                throw new Exception( __( 'This order cannot be paid 
for. Please contact us if you need assistance.', 'woocommerce' ) );
            }

Which is in file:

/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php

Which appears to reference a user capability.

What would be the best way of giving admins the capability to ‘pay_for_order’ for any order?

Many thanks for any help you can give

Upvotes: 1

Views: 3374

Answers (2)

dans_art
dans_art

Reputation: 43

If you are using the "User Role Editor" Plugin, you can do it without code. Just add the capability and make sure that the checkbox is activated for the desired role. Add capability screen

Checked capability

Upvotes: 0

Orlando P.
Orlando P.

Reputation: 631

This is a really rough example but it is what you are looking for. You can add this to your functions.php file. This will give the administrator role that capability.

function allow_admin_to_pay_for_order(){

     $administrator = get_role('administrator');
     $administrator->add_cap( 'pay_for_order' );
}

add_action('init', 'allow_admin_to_pay_for_order');

Upvotes: 5

Related Questions