Support » Plugin: License Manager for WooCommerce » Preserve the expire date when order completed

  • Resolved yueprofile

    (@yueprofile)


    When order complete, the expire date were lost.

    in license-manager-for-woocommerce/includes/integrations/woocommerce/Controller.php

    line 343 ‘expires_at’ => $expiresAt,

    however $expiresAt is initialized as null at line 331

    I suggest change to $expiresAt = $license->getExpiresAt();

    Changed version:

    /**
         * Mark the imported license keys as sold.
         *
         * @param LicenseResourceModel[] $licenses License key resource models
         * @param int                    $orderId  WooCommerce Order ID
         * @param int                    $amount   Amount to be marked as sold
         *
         * @throws Exception
         * @throws Exception
         */
        public function sellImportedLicenseKeys($licenses, $orderId, $amount)
        {
            $cleanLicenseKeys = $licenses;
            $cleanOrderId     = $orderId ? absint($orderId) : null;
            $cleanAmount      = $amount  ? absint($amount)  : null;
    
            if (!is_array($licenses) || count($licenses) <= 0) {
                throw new Exception('License Keys are invalid.');
            }
    
            if (!$cleanOrderId) {
                throw new Exception('Order ID is invalid.');
            }
    
            if (!$cleanOrderId) {
                throw new Exception('Amount is invalid.');
            }
    
            for ($i = 0; $i < $cleanAmount; $i++) {
                /** @var LicenseResourceModel $license */
                $license   = $cleanLicenseKeys[$i];
                $validFor  = intval($license->getValidFor());
                $expiresAt = $license->getExpiresAt();
    
                if ($validFor) {
                    $date         = new DateTime();
                    $dateInterval = new DateInterval('P' . $validFor . 'D');
                    $expiresAt    = $date->add($dateInterval)->format('Y-m-d H:i:s');
                }
    
                LicenseResourceRepository::instance()->update(
                    $license->getId(),
                    array(
                        'order_id'   => $cleanOrderId,
                        'expires_at' => $expiresAt,
                        'status'     => LicenseStatus::SOLD
                    )
                );
            }
        }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.