Replies: 0
Hi there,
I found the bit of code below on another post in this support forum which allows admins to pay for orders they have created for customers over the phone. It means you can click the ‘Customer Payment Page’ link to go to the Checkout/Order-pay page without needing to log in.
I first want to make sure that this is safe and doesn’t cause any security or privacy issues for the customer.
Secondly, if a customer calls to adjust an order they have already made online, or for example you need to add a fee to the order, you need to change the order status back to Payment Pending in order to edit the order like this. When adding an item or fee, it gives a new total for the whole order, and if taking payment as above they would be repaying the total again rather than just the additional charges. Is that right, or could someone clarify how additional fees/items are paid?
The code mentioned above is
function allow_payment_without_login( $allcaps, $caps, $args ) {
// Check we are looking at the WooCommerce Pay For Order Page
if ( !isset( $caps[0] ) || $caps[0] != 'pay_for_order' )
return $allcaps;
// Check that a Key is provided
if ( !isset( $_GET['key'] ) )
return $allcaps;
// Find the Related Order
$order = wc_get_order( $args[2] );
if( !$order )
return $allcaps; # Invalid Order
// Get the Order Key from the WooCommerce Order
$order_key = $order->get_order_key();
// Get the Order Key from the URL Query String
$order_key_check = $_GET['key'];
// Set the Permission to TRUE if the Order Keys Match
$allcaps['pay_for_order'] = ( $order_key == $order_key_check );
return $allcaps;
}
add_filter( 'user_has_cap', 'allow_payment_without_login', 10, 3 );