Skip to content

Commit

Permalink
👌 IMPROVE: Remove WooCommerce subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
austinginder committed Sep 7, 2024
1 parent 7275407 commit 3035d3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 54 deletions.
16 changes: 8 additions & 8 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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 ) );
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 0 additions & 45 deletions captaincore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand All @@ -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 );
Expand Down

0 comments on commit 3035d3d

Please sign in to comment.