Created
September 12, 2019 13:47
-
-
Save sisaacrussell/88fef76b059f213c811750b34fcfb50c to your computer and use it in GitHub Desktop.
Allow payment from WC generated invoice without login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Allow payment from WC generated invoice without login | |
* @see https://wordpress.org/support/topic/order-pay-without-login/ | |
*/ | |
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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment