mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-07 10:04:03 +00:00
Updates to 6.3.2
This commit is contained in:
@@ -626,7 +626,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
||||
wcs_copy_order_item( $item, $subscription_item );
|
||||
|
||||
// Don't include sign-up fees or $0 trial periods when setting the subscriptions item totals.
|
||||
$this->maybe_set_recurring_item_total( $subscription_item );
|
||||
wcs_set_recurring_item_total( $subscription_item );
|
||||
|
||||
$subscription_item->save();
|
||||
|
||||
@@ -718,41 +718,4 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
|
||||
|
||||
return rest_ensure_response( $subscriptions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subscription item total to its recurring product price.
|
||||
*
|
||||
* This function ensures that sign-up fees and/or $0 trial periods are not carried over from the initial order to the subscription.
|
||||
* Note: If the line item has a custom total set by the merchant, don't override it with the recurring price.
|
||||
*
|
||||
* @param WC_Order_Item $item Subscription line item.
|
||||
*
|
||||
*/
|
||||
private function maybe_set_recurring_item_total( &$item ) {
|
||||
$product = $item->get_product();
|
||||
|
||||
if ( ! $product ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product );
|
||||
$sign_up_fee = is_numeric( $sign_up_fee ) ? (float) $sign_up_fee : 0;
|
||||
$trial_length = WC_Subscriptions_Product::get_trial_length( $product );
|
||||
|
||||
$recurring_price = (float) $product->get_price();
|
||||
$initial_price = $trial_length > 0 ? $sign_up_fee : $recurring_price + $sign_up_fee;
|
||||
$initial_total = wc_get_price_excluding_tax( $product, [ 'qty' => $item->get_quantity(), 'price' => $initial_price ] );
|
||||
|
||||
// Check if a custom item total was set on the order. If so, don't override it.
|
||||
if ( (float) $item->get_subtotal() !== $initial_total ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$recurring_total = wc_get_price_excluding_tax( $product, [ 'qty' => $item->get_quantity(), 'price' => $recurring_price ] );
|
||||
|
||||
$item->set_props( [
|
||||
'subtotal' => $recurring_total,
|
||||
'total' => $recurring_total,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user