Emails
2 months ago
Integrations
2 months ago
MultichannelMarketing
2 years ago
TransactionalEmails
10 months ago
WooCommerceBookings
1 month ago
WooCommerceSubscriptions
2 months ago
CouponPreProcessor.php
2 months ago
Emails.php
8 months ago
Helper.php
1 month ago
MailPoetTask.php
2 years ago
NonPersistablePreviewData.php
1 month ago
OrderAttributionFields.php
1 month ago
OrderAttributionRevenueReader.php
2 weeks ago
OrderAttributionWriter.php
1 month ago
RandomCouponCodeGenerator.php
2 months ago
Settings.php
1 year ago
SubscriberEngagement.php
3 years ago
Subscription.php
2 months ago
Tracker.php
2 years ago
TransactionalEmailHooks.php
1 year ago
TransactionalEmails.php
1 year ago
WooSystemInfo.php
1 month ago
WooSystemInfoController.php
1 year ago
index.php
3 years ago
RandomCouponCodeGenerator.php
29 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\WooCommerce; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class RandomCouponCodeGenerator { |
| 9 | public function generate(): string { |
| 10 | return implode('-', [ |
| 11 | $this->generateSegment(4), |
| 12 | $this->generateSegment(6), |
| 13 | $this->generateSegment(4), |
| 14 | ]); |
| 15 | } |
| 16 | |
| 17 | private function generateSegment(int $length): string { |
| 18 | $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
| 19 | $maxIndex = strlen($characters) - 1; |
| 20 | $segment = ''; |
| 21 | |
| 22 | for ($i = 0; $i < $length; $i++) { |
| 23 | $segment .= $characters[random_int(0, $maxIndex)]; |
| 24 | } |
| 25 | |
| 26 | return $segment; |
| 27 | } |
| 28 | } |
| 29 |