Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created September 24, 2024 10:04
Show Gist options
  • Save kartikparmar/e22c911898298a8a9d2c3fa095da4be6 to your computer and use it in GitHub Desktop.
Save kartikparmar/e22c911898298a8a9d2c3fa095da4be6 to your computer and use it in GitHub Desktop.
Change subscription price.
<?php
function update_subscription_with_original_price( $subscription_id, $args ) {
global $wpdb;
// Get the download ID from the $args array
$download_id = $args['product_id'];
// Get the price ID if variable pricing is used
$price_id = ! empty( $args['price_id'] ) ? $args['price_id'] : null;
// Get the original price based on the price ID
if ( $price_id ) {
$original_price = edd_get_price_option_amount( $download_id, $price_id );
} else {
$original_price = edd_get_download_price( $download_id );
}
$discounted_price = $original_price - ($original_price * (25/100));
// Update the subscription's recurring amount directly in the database
$wpdb->update(
$wpdb->prefix . 'edd_subscriptions',
array( 'recurring_amount' => $discounted_price ),
array( 'id' => $subscription_id ),
array( '%f' ), // Data type for recurring_amount
array( '%d' ) // Data type for subscription ID
);
}
add_action( 'edd_subscription_post_create', 'update_subscription_with_original_price', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment