Skip to content

Commit

Permalink
fix(reader-revenue): initial order state with total of 0
Browse files Browse the repository at this point in the history
Because the order was created as completed, an email was sent right away
to the site admin, with a 0 as order total.
  • Loading branch information
adekbadek committed May 23, 2022
1 parent fee9e77 commit 7c30b09
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion includes/reader-revenue/class-woocommerce-connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ public static function set_up_membership( $email_address, $full_name, $frequency
public static function create_transaction( $order_data ) {
Logger::log( 'Creating an order' );

$order = wc_create_order( [ 'status' => 'completed' ] );
$frequency = $order_data['frequency'];

$item = self::get_donation_order_item( $frequency, $order_data['amount'] );
if ( false === $item ) {
return new WP_Error( 'newspack_woocommerce', __( 'Missing donation product.', 'newspack' ) );
}

$order = wc_create_order();
$order->add_item( $item );
$order->calculate_totals();
$order->set_currency( $order_data['currency'] );
Expand Down Expand Up @@ -148,6 +148,7 @@ public static function create_transaction( $order_data ) {
}

$order->set_created_via( 'newspack-stripe' );
$order->set_status( 'completed' );
$order->save();

if ( class_exists( 'WC_Memberships_Membership_Plans' ) ) {
Expand Down

0 comments on commit 7c30b09

Please sign in to comment.