-
Notifications
You must be signed in to change notification settings - Fork 17
fix: set order total 0 when vendor subscription trial active #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
fix: set order total 0 when vendor subscription trial active #26
Conversation
WalkthroughA filter hook is introduced to modify WooCommerce order totals for vendor subscription orders during their trial period. Two new methods are added: one to determine if an order is in a trial period, and another to set the order total to zero when the trial is active, based on user meta data and current date. Changes
Sequence Diagram(s)sequenceDiagram
participant Customer
participant WooCommerce
participant Dokan_Invoice
WooCommerce->>Dokan_Invoice: Apply wpo_wcpdf_woocommerce_totals filter
Dokan_Invoice->>Dokan_Invoice: get_woocommerce_totals_on_trail(totals, order)
Dokan_Invoice->>Dokan_Invoice: is_trial_period_active(user_id)
alt Trial period active
Dokan_Invoice->>WooCommerce: Set order total to zero
else Not in trial
Dokan_Invoice->>WooCommerce: Return original totals
end
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
dokan-invoice.php (1)
410-410
: Add type hints for consistencyFor consistency with the
is_trial_period_active
method, consider adding type hints to the method parameters.- public function get_woocommerce_totals_on_trail( $totals, $order ) { + public function get_woocommerce_totals_on_trial( array $totals, WC_Order $order ): array {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
dokan-invoice.php
(2 hunks)
🔇 Additional comments (2)
dokan-invoice.php (2)
434-446
: Fix date parsing inis_trial_period_active
The call tomodify()
treats$trial_until
as a relative format, but the meta value is almost certainly stored as an absolute timestamp (e.g. “2025-07-15 12:00:00”). This mismatch can yield incorrect comparisons or errors.Please verify how
_dokan_subscription_trial_until
is stored (date format and timezone) and update the method to parse it as an absolute date. For example:public function is_trial_period_active( $user_id ): bool { $trial_until = get_user_meta( $user_id, '_dokan_subscription_trial_until', true ); $is_on_trial = get_user_meta( $user_id, '_dokan_subscription_is_on_trial', true ); if ( $is_on_trial !== 'yes' || empty( $trial_until ) ) { return false; } $now = dokan_current_datetime(); // Parse stored absolute date instead of modifying now $trial_end = \DateTime::createFromFormat( 'Y-m-d H:i:s', $trial_until, $now->getTimezone() ); if ( ! $trial_end ) { // Invalid format — treat as not active return false; } return $trial_end > $now; }• Confirm the exact date format and timezone used when saving
_dokan_subscription_trial_until
.
• Replacemodify()
withcreateFromFormat()
(or adjust to match the stored format).
• Add error handling if parsing fails.
402-421
: Rename method and ensure vendor validation
- Rename
get_woocommerce_totals_on_trail
toget_woocommerce_totals_on_trial
to fix the typo.- Before zeroing out the total, verify that the customer is actually a vendor. For example, if Dokan provides
dokan_is_user_seller()
, use that; otherwise, use your vendor-lookup API:- public function get_woocommerce_totals_on_trail( $totals, $order ) { + public function get_woocommerce_totals_on_trial( $totals, $order ) { if ( $order->get_meta( '_dokan_vendor_subscription_order' ) !== 'yes' ) { return $totals; } $vendor_id = $order->get_customer_id(); + // Skip if this customer isn’t a registered vendor + if ( ! function_exists( 'dokan_is_user_seller' ) || ! dokan_is_user_seller( $vendor_id ) ) { + return $totals; + } if ( $this->is_trial_period_active( $vendor_id ) ) { $totals['order_total']['value'] = wc_price( 0, array( 'currency' => $order->get_currency() ) ); } return $totals; }Please verify that
dokan_is_user_seller()
(or an equivalent helper) exists in this codebase and returns true only for valid vendors.
@@ -184,6 +184,7 @@ public function init_hooks() { | |||
add_filter( 'wpo_wcpdf_shop_name', array( $this,'wpo_wcpdf_add_dokan_shop_name'), 10, 2 ); | |||
add_filter( 'wpo_wcpdf_shop_address', array( $this,'wpo_wcpdf_add_dokan_shop_details'), 10, 2 ); | |||
add_filter( 'wpo_wcpdf_check_privs', array( $this,'wpo_wcpdf_dokan_privs'), 50, 2 ); | |||
add_filter( 'wpo_wcpdf_woocommerce_totals', [ $this, 'get_woocommerce_totals_on_trail' ], 10, 2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in method name: "trail" should be "trial"
The method name get_woocommerce_totals_on_trail
contains a typo. It should be get_woocommerce_totals_on_trial
to maintain consistency with the domain terminology used throughout the codebase.
- add_filter( 'wpo_wcpdf_woocommerce_totals', [ $this, 'get_woocommerce_totals_on_trail' ], 10, 2 );
+ add_filter( 'wpo_wcpdf_woocommerce_totals', [ $this, 'get_woocommerce_totals_on_trial' ], 10, 2 );
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
add_filter( 'wpo_wcpdf_woocommerce_totals', [ $this, 'get_woocommerce_totals_on_trail' ], 10, 2 ); | |
add_filter( 'wpo_wcpdf_woocommerce_totals', [ $this, 'get_woocommerce_totals_on_trial' ], 10, 2 ); |
🤖 Prompt for AI Agents
In dokan-invoice.php at line 187, the method name used in the add_filter call
has a typo: "get_woocommerce_totals_on_trail" should be corrected to
"get_woocommerce_totals_on_trial" to match the correct terminology and maintain
consistency. Update the method name in the filter registration accordingly.
Issue