diff --git a/app/Account.php b/app/Account.php index 8f57ac5..de527c3 100644 --- a/app/Account.php +++ b/app/Account.php @@ -287,7 +287,7 @@ public function users() { "user_id" => $user->ID, "name" => $user->display_name, "email" => $user->user_email, - "level" => ucfirst( $permission->level ), + "level" => empty( $permission->level ) ? "" : ucfirst( $permission->level ), ]; } return $results; @@ -474,7 +474,7 @@ public function generate_order() { } } - if ( $plan->charges && count( $plan->charges ) > 0 ) { + if ( ! empty( $plan->charges ) && count( $plan->charges ) > 0 ) { foreach ( $plan->charges as $item ) { $line_item_id = $order->add_product( get_product( $configurations->woocommerce->charges ), $item->quantity ); $order->get_items()[ $line_item_id ]->set_subtotal( $item->price * $item->quantity ); @@ -486,7 +486,7 @@ public function generate_order() { } } - if ( $plan->credits && count( $plan->credits ) > 0 ) { + if ( ! empty( $plan->credits ) && count( $plan->credits ) > 0 ) { foreach ( $plan->credits as $item ) { $line_item_id = $order->add_product( get_product( $configurations->woocommerce->credits ), $item->quantity ); $order->get_items()[ $line_item_id ]->set_subtotal( -1 * abs( $item->price * $item->quantity ) ); @@ -615,8 +615,8 @@ public function failed_notify() { $recipient .= ", {$plan->additional_emails}"; } - $from_name = apply_filters( 'woocommerce_email_from_name', get_option( 'woocommerce_email_from_name' ), $this, $from_name ); - $from_email = apply_filters( 'woocommerce_email_from_address', get_option( 'woocommerce_email_from_address' ), $this, $from_email ); + $from_name = apply_filters( 'woocommerce_email_from_name', get_option( 'woocommerce_email_from_name' ), $this ); + $from_email = apply_filters( 'woocommerce_email_from_address', get_option( 'woocommerce_email_from_address' ), $this ); $headers = [ "Content-Type: text/html; charset=UTF-8", @@ -674,8 +674,8 @@ public function outstanding_notify() { $recipient .= ", {$plan->additional_emails}"; } - $from_name = apply_filters( 'woocommerce_email_from_name', get_option( 'woocommerce_email_from_name' ), $this, $from_name ); - $from_email = apply_filters( 'woocommerce_email_from_address', get_option( 'woocommerce_email_from_address' ), $this, $from_email ); + $from_name = apply_filters( 'woocommerce_email_from_name', get_option( 'woocommerce_email_from_name' ), $this ); + $from_email = apply_filters( 'woocommerce_email_from_address', get_option( 'woocommerce_email_from_address' ), $this ); $headers = [ "Content-Type: text/html; charset=UTF-8", @@ -722,7 +722,7 @@ public function auto_switch_plan() { } - if ( $plan->addons && count( $plan->addons ) > 0 ) { + if ( ! empty( $plan->addons ) && count( $plan->addons ) > 0 ) { foreach ( $plan->addons as $addon ) { $total += $addon->quantity * $addon->price; } diff --git a/app/Accounts.php b/app/Accounts.php index 5ddbfbd..daf53ba 100644 --- a/app/Accounts.php +++ b/app/Accounts.php @@ -121,7 +121,7 @@ public function process_renewals() { $plan->next_renewal = date("Y-m-d H:i:s", strtotime( "+{$plan->interval} month", $next_renewal ) ); unset( $plan->charges ); unset( $plan->credits ); - if ( $plan->over_payment ) { + if ( ! empty( $plan->over_payment ) ) { $plan->credits = [ (object) [ "name" => "Previous credits", diff --git a/captaincore.php b/captaincore.php index 388ba38..c7273dc 100755 --- a/captaincore.php +++ b/captaincore.php @@ -4265,36 +4265,6 @@ function cc_mime_types( $mimes ) { } add_filter( 'upload_mimes', 'cc_mime_types' ); -// After payment received, connect up the Stripe info into the subscription. -function captaincore_woocommerce_payment_complete( $order_id ) { - - $customer_id = get_field( '_customer_user', $order_id ); - $payment_tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id ); - - foreach ( $payment_tokens as $payment_token ) { - $token_id = $payment_token->get_token(); - } - - $payment_cus_id = get_field( '_stripe_customer_id', 'user_' . $customer_id ); - $payment_card_id = $token_id; - - // Find parent subscription id - if ( wcs_order_contains_subscription( $order_id ) ) { - $subscription = wcs_get_subscriptions_for_order( $order_id ); - $subscription_id = key( $subscription ); - } else { - $subscription_id = get_field( '_subscription_renewal', $order_id ); - } - - update_post_meta( $subscription_id, '_stripe_customer_id', $payment_cus_id ); - update_post_meta( $subscription_id, '_stripe_card_id', $payment_card_id ); - update_post_meta( $subscription_id, '_requires_manual_renewal', 'false' ); - update_post_meta( $subscription_id, '_payment_method', 'stripe' ); - update_post_meta( $subscription_id, '_payment_method_title', 'Credit card' ); - -} -add_action( 'woocommerce_payment_complete', 'captaincore_woocommerce_payment_complete' ); - // Custom payment link for speedy checkout function captaincore_get_checkout_payment_url( $payment_url ) { @@ -4316,21 +4286,6 @@ function captaincore_get_checkout_payment_url( $payment_url ) { function woocommerce_email_customer_invoice_add_recipients( $recipient, $order ) { - // Finds subscription for the order - $subscription = wcs_get_subscriptions_for_order( $order, [ 'order_type' => [ 'parent', 'renewal' ] ] ); - - if ( $subscription and array_values( $subscription )[0] ) { - // Find first subscription ID - $subscription_id = array_values( $subscription )[0]->id; - // Check ACF field for additional emails - $additional_emails = get_field( 'additional_emails', $subscription_id ); - - if ( $additional_emails ) { - // Found additional emails so add them to the $recipients list - $recipient .= ', ' . $additional_emails; - } - } - // Finds CaptainCore account $account_id = $order->get_meta( 'captaincore_account_id' ); $account = ( new CaptainCore\Accounts )->get( $account_id );