Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions dokan-invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

}

/**
Expand Down Expand Up @@ -398,6 +399,52 @@ public function get_order_id_parent_id( $document = null ) {
return compact('order_id','parent_id');
}

/**
* Modify WooCommerce totals for trial period subscriptions.
*
* @param array $totals WooCommerce totals
* @param WC_Order $order Order object
*
* @return array
*/
public function get_woocommerce_totals_on_trail( $totals, $order ) {
if ( $order->get_meta( '_dokan_vendor_subscription_order' ) !== 'yes' ) {
return $totals;
}

$vendor_id = $order->get_customer_id();
if ( $this->is_trial_period_active( $vendor_id ) ) {
$totals['order_total']['value'] = wc_price( 0, array( 'currency' => $order->get_currency() ) );
}

return $totals;
}

/**
* Check if a vendor's subscription trial period is active.
*
* This method retrieves the trial end date and trial status stored in user meta
* and compares the trial end date with the current date and time to determine
* if the trial period is still active.
*
* @param int $user_id The ID of the user (vendor) to check for an active trial period.
*
* @return bool True if the trial period is active, false otherwise.
*/
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;
}

$time = dokan_current_datetime();
$time = $time->modify( $trial_until );

return $time > dokan_current_datetime();
}

}

$dokan_invoice = Dokan_Invoice::init();