Есть похожая тема, но она работает только для Woocommerce.Мне нужно, чтобы он работал с подписками Woocommerce.
URL-адрес немного отличается для подписки: your.domain/checkout/order-pay/987/? pay_for_order=true&key=wc_order_5c4155dd4462c&subscription_renewal=true
Я попытался добавить следующее:
$allcaps['pay_for_order'] = ( $order_key == $order_key_check );
$allcaps['subscription_renewal'] = ( $order_key == $order_key_check );
Мой код функции:
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 );