Automattic\WooCommerce\Gateways\PayPal
Helper::get_wc_order_from_paypal_custom_id
Get the WC order from the PayPal custom ID.
Method of the class: Helper{}
No Hooks.
Returns
WC_Order|null.
Usage
$result = Helper::get_wc_order_from_paypal_custom_id( $custom_id ): ?WC_Order;
- $custom_id(string) (required)
- The custom ID string from the PayPal order.
Helper::get_wc_order_from_paypal_custom_id() Helper::get wc order from paypal custom id code WC 10.8.1
public static function get_wc_order_from_paypal_custom_id( string $custom_id ): ?WC_Order {
if ( '' === $custom_id ) {
return null;
}
$data = json_decode( $custom_id, true );
if ( ! is_array( $data ) ) {
return null;
}
$order_id = $data['order_id'] ?? null;
if ( ! $order_id ) {
return null;
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof \WC_Order ) {
return null;
}
// Validate the order key.
$order_key = $data['order_key'] ?? null;
if ( $order_key !== $order->get_order_key() ) {
return null;
}
return $order;
}