mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-17 23:02:56 +00:00
2.2.3
This commit is contained in:

committed by
Remco Tolsma

parent
a7af434d12
commit
0691aa36da
@@ -104,16 +104,31 @@ class WCS_Webhooks {
|
||||
public static function create_payload( $payload, $resource, $resource_id, $id ) {
|
||||
|
||||
if ( 'subscription' == $resource && empty( $payload ) && wcs_is_subscription( $resource_id ) ) {
|
||||
|
||||
$webhook = new WC_Webhook( $id );
|
||||
$event = $webhook->get_event();
|
||||
$current_user = get_current_user_id();
|
||||
|
||||
wp_set_current_user( $webhook->get_user_id() );
|
||||
|
||||
WC()->api->WC_API_Subscriptions->register_routes( array() );
|
||||
$webhook_api_version = ( method_exists( $webhook, 'get_api_version' ) ) ? $webhook->get_api_version() : 'legacy_v3';
|
||||
|
||||
$payload = WC()->api->WC_API_Subscriptions->get_subscription( $resource_id );
|
||||
switch ( $webhook_api_version ) {
|
||||
case 'legacy_v3':
|
||||
WC()->api->WC_API_Subscriptions->register_routes( array() );
|
||||
$payload = WC()->api->WC_API_Subscriptions->get_subscription( $resource_id );
|
||||
break;
|
||||
case 'wp_api_v1':
|
||||
case 'wp_api_v2':
|
||||
require_once( 'api/class-wc-rest-subscriptions-controller.php' );
|
||||
|
||||
$request = new WP_REST_Request( 'GET' );
|
||||
$controller = new WC_REST_Subscriptions_Controller;
|
||||
|
||||
$request->set_param( 'id', $resource_id );
|
||||
$result = $controller->get_item( $request );
|
||||
$payload = isset( $result->data ) ? $result->data : array();
|
||||
break;
|
||||
}
|
||||
|
||||
wp_set_current_user( $current_user );
|
||||
}
|
||||
@@ -154,7 +169,7 @@ class WCS_Webhooks {
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function add_subscription_created_callback( $subscription ) {
|
||||
do_action( 'wcs_webhook_subscription_created', $subscription->id );
|
||||
do_action( 'wcs_webhook_subscription_created', $subscription->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +178,7 @@ class WCS_Webhooks {
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function add_subscription_updated_callback( $subscription ) {
|
||||
do_action( 'wcs_webhook_subscription_updated', $subscription->id );
|
||||
do_action( 'wcs_webhook_subscription_updated', $subscription->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user