Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › Apply Coupon To Exisitng Subscriber
- This topic has 8 replies, 4 voices, and was last updated 2 years, 7 months ago by ArcPro Support.
-
AuthorPosts
-
May 9, 2020 at 11:57 am #15571Heidi MaskelyneParticipant
is there a way to apply a coupon to an already ongoing subscription so the subscriber on there next renewal date gets the applied auto coupon discount ?
May 9, 2020 at 3:36 pm #15572Soft79KeymasterI don’t know, we don’t use the subscriptions plugin.
May 10, 2020 at 3:28 pm #15576Angela MauricetteParticipantHi, For some reason the plugin cannot be installed into my website…
this is what I got for message:
Unpacking the package…Installing the plugin…
The package could not be installed. No valid plugins were found.
Plugin installation failed.
May 10, 2020 at 3:28 pm #15577Angela MauricetteParticipantHi, For some reason the plugin cannot be installed into my website…
this is what I got for message:
Unpacking the package…Installing the plugin…
The package could not be installed. No valid plugins were found.
Plugin installation failed.
May 10, 2020 at 8:27 pm #15578Soft79KeymasterHi Angela,
Strange, I can see that you downloaded the right file. You should have created a new topic instead of ‘hijacking’ someone elses unrelated thread on this forum, but I will answer the email you sent me.
May 15, 2020 at 4:50 pm #15615Heidi MaskelyneParticipantHi again ,
I know we can hook into renewals below code which is good but how can I check through all coupons to see if the subscriber has a valid coupon to use ?
function apply_discount_on_renewal_order_created( $renewal_order, $subscription ) { $order = new WC_Order( $renewal_order->get_id() ); $coupon_amount = 25; $order->set_total( $order->get_total() - $coupon_amount ); return $order; } add_filter( 'wcs_renewal_order_created', 'apply_discount_on_renewal_order_created', 10, 2 );
May 15, 2020 at 5:18 pm #15616Soft79KeymasterTo see how our plugin does that, you can take a peek at the get_valid_auto_coupons() function in includes/plugins/WJECF_Autocoupon.php .
May 16, 2020 at 10:22 am #15618Heidi MaskelyneParticipantthank you for your help
for anyone that needs this functionality you can adjust the code below to suit your needs
// discount subscription renewals function discount_subscription_renewals($billing_email){ $query_args = array( 'posts_per_page' => -1, 'post_type' => 'shop_coupon', 'post_status' => 'publish', 'orderby' => array( 'title' => 'ASC' ), 'meta_query' => array( array( 'key' => 'discount_type', 'value' => 'fixed_cart', ), ), ); $coupons = get_posts( $query_args ); $coupon_code = false; $discount = 0; foreach ( $coupons as $coupon ) { $customer_email = array($coupon->customer_email[0]); $amount = $coupon->coupon_amount; $usage_count = $coupon->usage_count; $usage_limit = $coupon->usage_limit; if (in_array($billing_email,$customer_email) && ($usage_count < $usage_limit)){ $coupon_code = $coupon->post_title; break; //$discount += $amount; } } return $coupon_code; } function apply_discount_on_renewal_order_created( $renewal_order, $subscription ) { $order = new WC_Order($renewal_order->get_id() ); $billing_email = $order->get_billing_email(); $coupon_code = discount_subscription_renewals($billing_email); if ($coupon_code){ $order->apply_coupon($coupon_code); //$order->set_total( $order->get_total() - $coupon_amount ); } return $order; } add_filter( 'wcs_renewal_order_created', 'apply_discount_on_renewal_order_created', 10, 2 );
February 3, 2021 at 11:38 pm #17251ArcPro SupportParticipantHI there,
I am seeing an error when I am trying to upload my purchased plugin to my WordPress website. The error I see is:
Unpacking the package…
Installing the plugin…
The package could not be installed. No valid plugins were found.
Plugin installation failed.
-
AuthorPosts
- You must be logged in to reply to this topic.