Skip to content

Instantly share code, notes, and snippets.

@saimonh3
Created September 22, 2019 03:29
Show Gist options
  • Save saimonh3/e7addea7ce894721b785a91ad38c8ea7 to your computer and use it in GitHub Desktop.
Save saimonh3/e7addea7ce894721b785a91ad38c8ea7 to your computer and use it in GitHub Desktop.
Test Subscription
if ( 'invoice.payment_succeeded' == $event->type ) {
$user_id = $wpdb->get_var( "SELECT `user_id` FROM $wpdb->usermeta WHERE `meta_key` = '_stripe_subscription_id' AND `meta_value`='$invoice->subscription'" );
$period_start = date( 'Y-m-d H:i:s', $invoice->period_start );
$period_end = date( 'Y-m-d H:i:s', $invoice->period_end );
$order_id = get_user_meta( $user_id, 'product_order_id', true );
if ( $invoice->paid ) {
update_user_meta( $user_id, 'product_pack_startdate', $period_start );
update_user_meta( $user_id, 'product_pack_enddate', $period_end );
update_user_meta( $user_id, 'can_post_product', '1' );
update_user_meta( $user_id, 'has_pending_subscription', false );
if ( !empty( $invoice->charge ) ) {
update_post_meta( $order_id, '_stripe_subscription_charge_id', $invoice->charge );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment