Created
June 20, 2019 23:47
-
-
Save JPry/1661079fa689c92c3e2cc25946edc2d8 to your computer and use it in GitHub Desktop.
Code snippet to allow customers to pay for an order without logging in.
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
<?php | |
/** | |
* Allow orders created by an admin to be paid without the user logging in. | |
* | |
* @param array $allcaps All capabilities of the user. | |
* @param array $caps Capabilities requested. | |
* @param array $args Extra Arguments. | |
* | |
* @return array The filtered capabilities of the user. | |
*/ | |
function jp_custom_order_caps( $allcaps, $caps, $args ) { | |
if ( ! isset( $caps[0], $args[2] ) ) { | |
return $allcaps; | |
} | |
switch ( $caps[0] ) { | |
case 'pay_for_order': | |
$order = wc_get_order( $args[2] ); | |
if ( 'admin' === $order->get_created_via() ) { | |
$allcaps['pay_for_order'] = true; | |
} | |
break; | |
} | |
return $allcaps; | |
} | |
add_filter( 'user_has_cap', 'jp_custom_order_caps', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment