| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Helpers; |
| 4 |
|
| 5 |
use FluentCart\Api\ModuleSettings; |
| 6 |
use FluentCart\App\App; |
| 7 |
|
| 8 |
class EditorShortCodeHelper |
| 9 |
{ |
| 10 |
public static function getGeneralShortCodes(): array |
| 11 |
{ |
| 12 |
return [ |
| 13 |
'title' => __('General', 'fluent-cart'), |
| 14 |
'key' => 'wp', |
| 15 |
'shortcodes' => [ |
| 16 |
'{{wp.admin_email}}' => __('Admin Email', 'fluent-cart'), |
| 17 |
'{{wp.site_url}}' => __('Site URL', 'fluent-cart'), |
| 18 |
'{{wp.site_title}}' => __('Site Title', 'fluent-cart'), |
| 19 |
'{{user.ID}}' => __('User ID', 'fluent-cart'), |
| 20 |
'{{user.display_name}}' => __('User Display Name', 'fluent-cart'), |
| 21 |
'{{user.first_name}}' => __('User First Name', 'fluent-cart'), |
| 22 |
'{{user.last_name}}' => __('User Last Name', 'fluent-cart'), |
| 23 |
'{{user.user_email}}' => __('User Email', 'fluent-cart'), |
| 24 |
'{{user.user_login}}' => __('User Username', 'fluent-cart') |
| 25 |
], |
| 26 |
]; |
| 27 |
} |
| 28 |
|
| 29 |
public static function getSettingsShortCodes(): array |
| 30 |
{ |
| 31 |
return [ |
| 32 |
'title' => __('Settings', 'fluent-cart'), |
| 33 |
'key' => 'settings', |
| 34 |
'shortcodes' => [ |
| 35 |
'{{settings.store_name}}' => __('Store Name', 'fluent-cart'), |
| 36 |
'{{settings.store_logo}}' => __('Store Logo', 'fluent-cart'), |
| 37 |
'{{settings.store_address}}' => __('Store Address Line 1', 'fluent-cart'), |
| 38 |
'{{settings.store_address2}}' => __('Store Address Line 2', 'fluent-cart'), |
| 39 |
'{{settings.store_country}}' => __('Store Country', 'fluent-cart'), |
| 40 |
'{{settings.store_state}}' => __('Store State', 'fluent-cart'), |
| 41 |
'{{settings.store_city}}' => __('Store City', 'fluent-cart'), |
| 42 |
'{{settings.store_postcode}}' => __('Store Postcode', 'fluent-cart'), |
| 43 |
'{{settings.company_name}}' => __('Company Name', 'fluent-cart'), |
| 44 |
'{{settings.legal_registration_id}}' => __('Legal Registration ID', 'fluent-cart'), |
| 45 |
'{{settings.seller_vat_id}}' => __('Seller VAT ID', 'fluent-cart'), |
| 46 |
'{{settings.seller_tax_id}}' => __('Seller Tax ID', 'fluent-cart'), |
| 47 |
], |
| 48 |
'group' => 'settings' |
| 49 |
]; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
static function collectShortcodeFromNestedTextFields($array, $prefix = '') |
| 54 |
{ |
| 55 |
$text_fields = []; |
| 56 |
|
| 57 |
foreach ($array as $key => $value) { |
| 58 |
if (is_array($value)) { |
| 59 |
if (isset($value['type']) && $value['type'] === 'text' && isset($value['label'])) { |
| 60 |
$label = isset($value['label']) && $value['label'] |
| 61 |
? $value['label'] |
| 62 |
: ucwords(str_replace('_', ' ', $key)); |
| 63 |
|
| 64 |
$text_fields['{{' . $prefix . '.' . $key . '}}'] = $label; |
| 65 |
} elseif (isset($value['schema'])) { |
| 66 |
$text_fields = array_merge($text_fields, static::collectShortcodeFromNestedTextFields($value['schema'], $prefix)); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
return $text_fields; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Make shortCodes from array |
| 76 |
* @array array [ key => [ ... arguments] ] |
| 77 |
* @parentKey string will add to the key of array label |
| 78 |
* @type $type string 'keyPair', will only return a key and label (string) array |
| 79 |
* @return array array of shortCodes Exm: [ {{my.shortcode}} => 'My Shortcode' ] |
| 80 |
*/ |
| 81 |
public static function makeShortCodes(array $array, $parentKey = '', $type = ''): array |
| 82 |
{ |
| 83 |
$result = []; |
| 84 |
foreach ($array as $key => $value) { |
| 85 |
$newKey = $parentKey ? $parentKey . '.' . $key : $key; |
| 86 |
if (isset($value['label'])) { |
| 87 |
$title = $value['label'] . ' (' . $parentKey . ')'; |
| 88 |
$code = '{{' . $newKey . '}}'; |
| 89 |
if ($type === 'keyPair') { |
| 90 |
$result[$code] = $title; |
| 91 |
} else { |
| 92 |
$value['attributes'] = [ |
| 93 |
'code' => '{{' . $newKey . '}}', |
| 94 |
'type' => $value['data-type'], |
| 95 |
'name' => $value['label'] . ' (' . $parentKey . ')' |
| 96 |
]; |
| 97 |
$result[$newKey] = $value; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
return $result; |
| 104 |
} |
| 105 |
|
| 106 |
public static function checkoutInputs(): array |
| 107 |
{ |
| 108 |
$cartCheckoutHelper = CartCheckoutHelper::make(); |
| 109 |
|
| 110 |
return array_merge( |
| 111 |
static::makeShortCodes($cartCheckoutHelper->getBillingAddressFields(), 'billing'), |
| 112 |
static::makeShortCodes($cartCheckoutHelper->getShippingAddressFields(), 'shipping') |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
public static function conditionalInputs() |
| 117 |
{ |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
public static function getCustomerShortCodesForOrder(): array |
| 122 |
{ |
| 123 |
$cartCheckoutHelper = CartCheckoutHelper::make(); |
| 124 |
$billingFields = $cartCheckoutHelper->getBillingAddressFields(); |
| 125 |
|
| 126 |
$shippingFields = $cartCheckoutHelper->getShippingAddressFields(); |
| 127 |
|
| 128 |
// $shortCodes = array_merge( |
| 129 |
// static::collectShortcodeFromNestedTextFields($billingFields, 'billing'), |
| 130 |
// static::collectShortcodeFromNestedTextFields($shippingFields, 'shipping') |
| 131 |
// ); |
| 132 |
|
| 133 |
$shortCodes = array_merge( |
| 134 |
static::collectShortcodeFromNestedTextFields($billingFields, 'order.billing'), |
| 135 |
[ |
| 136 |
'{{order.billing.city}}' => __('City', 'fluent-cart'), |
| 137 |
'{{order.billing.state}}' => __('State', 'fluent-cart'), |
| 138 |
'{{order.billing.postcode}}' => __('Postcode', 'fluent-cart'), |
| 139 |
'{{order.billing.country}}' => __('Country', 'fluent-cart'), |
| 140 |
'{{order.billing.address_1}}' => __('Address Line 1', 'fluent-cart'), |
| 141 |
'{{order.billing.address_2}}' => __('Address Line 2', 'fluent-cart'), |
| 142 |
], |
| 143 |
static::collectShortcodeFromNestedTextFields($shippingFields, 'order.shipping'), |
| 144 |
[ |
| 145 |
'{{order.shipping.city}}' => __('City', 'fluent-cart'), |
| 146 |
'{{order.shipping.state}}' => __('State', 'fluent-cart'), |
| 147 |
'{{order.shipping.postcode}}' => __('Postcode', 'fluent-cart'), |
| 148 |
'{{order.shipping.country}}' => __('Country', 'fluent-cart'), |
| 149 |
'{{order.shipping.address_1}}' => __('Address Line 1', 'fluent-cart'), |
| 150 |
'{{order.shipping.address_2}}' => __('Address Line 2', 'fluent-cart'), |
| 151 |
] |
| 152 |
); |
| 153 |
|
| 154 |
|
| 155 |
return [ |
| 156 |
'key' => 'customer', |
| 157 |
'title' => 'Customer', |
| 158 |
'shortcodes' => $shortCodes |
| 159 |
]; |
| 160 |
} |
| 161 |
|
| 162 |
public static function getPaymentShortCodes(): array |
| 163 |
{ |
| 164 |
$orderProperties = [ |
| 165 |
|
| 166 |
]; |
| 167 |
|
| 168 |
return [ |
| 169 |
'key' => 'payment', |
| 170 |
'title' => 'Payments', |
| 171 |
'shortcodes' => $orderProperties, |
| 172 |
]; |
| 173 |
} |
| 174 |
|
| 175 |
public static function getTransactionShortCodes(): array |
| 176 |
{ |
| 177 |
$orderProperties = [ |
| 178 |
'{{transaction.total}}' => __('Total Amount', 'fluent-cart'), |
| 179 |
'{{transaction.total_formatted}}' => __('Total Amount (Formatted)', 'fluent-cart'), |
| 180 |
'{{transaction.refund_amount}}' => __('Refund Amount', 'fluent-cart'), |
| 181 |
'{{transaction.refund_amount_formatted}}' => __('Refund Amount (Formatted)', 'fluent-cart'), |
| 182 |
'{{transaction.payment_method}}' => __('Payment Method', 'fluent-cart'), |
| 183 |
'{{transaction.card_last_4}}' => __('Card Last 4', 'fluent-cart'), |
| 184 |
'{{transaction.card_brand}}' => __('Card Brand', 'fluent-cart'), |
| 185 |
'{{transaction.status}}' => __('Status', 'fluent-cart'), |
| 186 |
'{{transaction.currency}}' => __('Currency', 'fluent-cart'), |
| 187 |
]; |
| 188 |
|
| 189 |
return [ |
| 190 |
'title' => 'transaction', |
| 191 |
'key' => 'settings', |
| 192 |
'shortcodes' => $orderProperties, |
| 193 |
]; |
| 194 |
} |
| 195 |
|
| 196 |
public static function getShortCodes(): array |
| 197 |
{ |
| 198 |
$groups = [ |
| 199 |
static::getCustomerShortCodesForOrder(), |
| 200 |
static::getOrderShortCodes(), |
| 201 |
static::getGeneralShortCodes(), |
| 202 |
static::getSettingsShortCodes(), |
| 203 |
]; |
| 204 |
|
| 205 |
$groups = apply_filters('fluent_cart/confirmation_shortcodes', $groups, []); |
| 206 |
|
| 207 |
$data = [ |
| 208 |
'data' => $groups |
| 209 |
]; |
| 210 |
|
| 211 |
return $data; |
| 212 |
} |
| 213 |
|
| 214 |
public static function getOrderShortCodes(): array |
| 215 |
{ |
| 216 |
return [ |
| 217 |
'title' => __('Order', 'fluent-cart'), |
| 218 |
'key' => 'order', |
| 219 |
'shortcodes' => [ |
| 220 |
'{{order.id}}' => __('Order ID', 'fluent-cart'), |
| 221 |
'{{order.customer_dashboard_link}}' => __('Customer Dashboard Link', 'fluent-cart'), |
| 222 |
'{{order.payment_link}}' => __('Order Payment Link', 'fluent-cart'), |
| 223 |
'{{order.status}}' => __('Order Status', 'fluent-cart'), |
| 224 |
'{{order.parent_id}}' => __('Order Parent Id', 'fluent-cart'), |
| 225 |
'{{order.invoice_no}}' => __('Order Number', 'fluent-cart'), |
| 226 |
'{{order.fulfillment_type}}' => __('Order Fulfillment Type', 'fluent-cart'), |
| 227 |
'{{order.type}}' => __('Order Type', 'fluent-cart'), |
| 228 |
'{{order.customer_id}}' => __('Order Customer Id', 'fluent-cart'), |
| 229 |
'{{order.payment_method}}' => __('Order Payment Method', 'fluent-cart'), |
| 230 |
'{{order.payment_method_title}}' => __('Order Payment Method Title', 'fluent-cart'), |
| 231 |
'{{order.payment_status}}' => __('Order Payment Status', 'fluent-cart'), |
| 232 |
'{{order.currency}}' => __('Order Currency', 'fluent-cart'), |
| 233 |
'{{order.subtotal}}' => __('Order Subtotal', 'fluent-cart'), |
| 234 |
'{{order.subtotal_formatted}}' => __('Order Subtotal (Formatted)', 'fluent-cart'), |
| 235 |
'{{order.discount_tax}}' => __('Order Discount Tax', 'fluent-cart'), |
| 236 |
'{{order.discount_tax_formatted}}' => __('Order Discount Tax (Formatted)', 'fluent-cart'), |
| 237 |
'{{order.discount_total}}' => __('Order Discount Total', 'fluent-cart'), |
| 238 |
'{{order.discount_total_formatted}}' => __('Order Discount Total (Formatted)', 'fluent-cart'), |
| 239 |
'{{order.manual_discount_total}}' => __('Manual Discount Total', 'fluent-cart'), |
| 240 |
'{{order.manual_discount_total_formatted}}' => __('Manual Discount Total (Formatted)', 'fluent-cart'), |
| 241 |
'{{order.coupon_discount_total}}' => __('Coupon Discount Total', 'fluent-cart'), |
| 242 |
'{{order.coupon_discount_total_formatted}}' => __('Coupon Discount Total (Formatted)', 'fluent-cart'), |
| 243 |
'{{order.shipping_tax}}' => __('Order Shipping Tax', 'fluent-cart'), |
| 244 |
'{{order.shipping_tax_formatted}}' => __('Order Shipping Tax (Formatted)', 'fluent-cart'), |
| 245 |
'{{order.shipping_total}}' => __('Order Shipping Total', 'fluent-cart'), |
| 246 |
'{{order.shipping_total_formatted}}' => __('Order Shipping Total (Formatted)', 'fluent-cart'), |
| 247 |
'{{order.tax_total}}' => __('Order Tax Total', 'fluent-cart'), |
| 248 |
'{{order.tax_total_formatted}}' => __('Order Tax Total (Formatted)', 'fluent-cart'), |
| 249 |
'{{order.tax_breakdown}}' => __('Order Tax Breakdown', 'fluent-cart'), |
| 250 |
'{{order.fee_lines}}' => __('Order Fee Lines', 'fluent-cart'), |
| 251 |
'{{order.total_amount}}' => __('Order Total Amount', 'fluent-cart'), |
| 252 |
'{{order.total_amount_formatted}}' => __('Order Total Amount (Formatted)', 'fluent-cart'), |
| 253 |
'{{order.total_paid}}' => __('Order Total Paid', 'fluent-cart'), |
| 254 |
'{{order.total_paid_formatted}}' => __('Order Total Paid (Formatted)', 'fluent-cart'), |
| 255 |
'{{order.total_refund}}' => __('Order Total Refund', 'fluent-cart'), |
| 256 |
'{{order.total_refund_formatted}}' => __('Order Total Refund (Formatted)', 'fluent-cart'), |
| 257 |
'{{order.rate}}' => __('Order Rate', 'fluent-cart'), |
| 258 |
'{{order.note}}' => __('Order Note', 'fluent-cart'), |
| 259 |
'{{order.ip_address}}' => __('Order Ip Address', 'fluent-cart'), |
| 260 |
'{{order.completed_at}}' => __('Order Completed At', 'fluent-cart'), |
| 261 |
'{{order.refunded_at}}' => __('Order Refunded At', 'fluent-cart'), |
| 262 |
'{{order.uuid}}' => __('Order UUID', 'fluent-cart'), |
| 263 |
'{{order.payment_receipt}}' => __('Payment Receipt', 'fluent-cart'), |
| 264 |
'{{order.payment_summary}}' => __('Payment Summary', 'fluent-cart'), |
| 265 |
'{{order.downloads}}' => __('Order Downloads', 'fluent-cart'), |
| 266 |
'{{order.created_at}}' => __('Order Create Date', 'fluent-cart'), |
| 267 |
'{{order.item_count}}' => __('Order Item Count', 'fluent-cart'), |
| 268 |
'{{order.is_digital}}' => __('Is Digital Order', 'fluent-cart'), |
| 269 |
'{{order.buyer_company_name}}' => __('Buyer Company Name', 'fluent-cart'), |
| 270 |
'{{order.buyer_vat_display}}' => __('Buyer VAT / Tax ID (formatted)', 'fluent-cart'), |
| 271 |
'{{order.buyer_legal_registration_id}}' => __('Buyer Legal Registration ID', 'fluent-cart'), |
| 272 |
'{{order.buyer_reverse_charge_declaration}}' => __('Buyer Reverse Charge Declaration', 'fluent-cart'), |
| 273 |
'{{order.store_vat_display}}' => __('Store VAT Number (formatted)', 'fluent-cart'), |
| 274 |
'{{order.store_company_name}}' => __('Store Company Name', 'fluent-cart'), |
| 275 |
'{{order.store_company_display}}' => __('Store Company Name (formatted)', 'fluent-cart'), |
| 276 |
'{{order.store_legal_registration_id}}' => __('Store Legal Registration ID', 'fluent-cart'), |
| 277 |
'{{order.store_legal_registration_display}}' => __('Store Legal Registration ID (formatted)', 'fluent-cart'), |
| 278 |
'{{order.store_seller_vat_id}}' => __('Store Seller VAT ID', 'fluent-cart'), |
| 279 |
'{{order.store_seller_vat_display}}' => __('Store Seller VAT ID (formatted)', 'fluent-cart'), |
| 280 |
'{{order.store_seller_tax_id}}' => __('Store Seller Tax ID', 'fluent-cart'), |
| 281 |
'{{order.store_tax_display}}' => __('Store Seller Tax ID (formatted)', 'fluent-cart'), |
| 282 |
], |
| 283 |
]; |
| 284 |
} |
| 285 |
|
| 286 |
public static function getEmailNotificationShortcodes(): array |
| 287 |
{ |
| 288 |
|
| 289 |
$shortCodes = [ |
| 290 |
'order' => static::getOrderShortCodes(), |
| 291 |
'general' => static::getGeneralShortCodes(), |
| 292 |
'customer' => static::getCustomerShortCodesForOrder(), |
| 293 |
'transaction' => static::getTransactionShortCodes(), |
| 294 |
'settings' => static::getSettingsShortCodes(), |
| 295 |
'license' => static::getLicenseShortCodes(), |
| 296 |
]; |
| 297 |
return apply_filters('fluent_cart/editor_shortcodes', $shortCodes); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
public static function getEmailSettingsShortcodes(): array |
| 302 |
{ |
| 303 |
return [ |
| 304 |
static::getGeneralShortCodes(), |
| 305 |
static::getSettingsShortCodes() |
| 306 |
]; |
| 307 |
} |
| 308 |
|
| 309 |
public static function getItemShortCodes(): array |
| 310 |
{ |
| 311 |
return [ |
| 312 |
'title' => __('Order Item (Loop)', 'fluent-cart'), |
| 313 |
'key' => 'item', |
| 314 |
'shortcodes' => [ |
| 315 |
'{{item.sl}}' => __('Serial Number', 'fluent-cart'), |
| 316 |
'{{item.name}}' => __('Product Name', 'fluent-cart'), |
| 317 |
'{{item.variant}}' => __('Variant Name', 'fluent-cart'), |
| 318 |
'{{item.quantity}}' => __('Quantity', 'fluent-cart'), |
| 319 |
'{{item.unit_price}}' => __('Unit Price', 'fluent-cart'), |
| 320 |
'{{item.unit_price_formatted}}' => __('Unit Price (Formatted)', 'fluent-cart'), |
| 321 |
'{{item.price}}' => __('Total Price', 'fluent-cart'), |
| 322 |
'{{item.price_formatted}}' => __('Total Price (Formatted)', 'fluent-cart'), |
| 323 |
'{{item.subtotal}}' => __('Subtotal', 'fluent-cart'), |
| 324 |
'{{item.subtotal_formatted}}' => __('Subtotal (Formatted)', 'fluent-cart'), |
| 325 |
'{{item.payment_info}}' => __('Payment Info', 'fluent-cart'), |
| 326 |
'{{item.payment_type}}' => __('Payment Type', 'fluent-cart'), |
| 327 |
], |
| 328 |
]; |
| 329 |
} |
| 330 |
|
| 331 |
public static function getLicenseShortCodes(): array |
| 332 |
{ |
| 333 |
return [ |
| 334 |
'title' => __('License (Loop)', 'fluent-cart'), |
| 335 |
'key' => 'license', |
| 336 |
'shortcodes' => [ |
| 337 |
'{{license.sl}}' => __('Serial Number', 'fluent-cart'), |
| 338 |
'{{license.key}}' => __('License Key', 'fluent-cart'), |
| 339 |
'{{license.status}}' => __('Status', 'fluent-cart'), |
| 340 |
'{{license.product_name}}' => __('Product Name', 'fluent-cart'), |
| 341 |
'{{license.variant}}' => __('Variant', 'fluent-cart'), |
| 342 |
'{{license.limit}}' => __('Activation Limit', 'fluent-cart'), |
| 343 |
'{{license.activation_count}}' => __('Activation Count', 'fluent-cart'), |
| 344 |
'{{license.expiration_date}}' => __('Expiration Date', 'fluent-cart'), |
| 345 |
], |
| 346 |
]; |
| 347 |
} |
| 348 |
|
| 349 |
public static function getDownloadShortCodes(): array |
| 350 |
{ |
| 351 |
return [ |
| 352 |
'title' => __('Download (Loop)', 'fluent-cart'), |
| 353 |
'key' => 'download', |
| 354 |
'shortcodes' => [ |
| 355 |
'{{download.sl}}' => __('Serial Number', 'fluent-cart'), |
| 356 |
'{{download.title}}' => __('File Title', 'fluent-cart'), |
| 357 |
'{{download.product_name}}' => __('Product Name', 'fluent-cart'), |
| 358 |
'{{download.url}}' => __('Download URL', 'fluent-cart'), |
| 359 |
'{{download.file_size}}' => __('File Size', 'fluent-cart'), |
| 360 |
], |
| 361 |
]; |
| 362 |
} |
| 363 |
|
| 364 |
public static function getSubscriptionShortCodes(): array |
| 365 |
{ |
| 366 |
return [ |
| 367 |
'title' => __('Subscription (Loop)', 'fluent-cart'), |
| 368 |
'key' => 'subscription', |
| 369 |
'shortcodes' => [ |
| 370 |
'{{subscription.sl}}' => __('Serial Number', 'fluent-cart'), |
| 371 |
'{{subscription.item_name}}' => __('Item Name', 'fluent-cart'), |
| 372 |
'{{subscription.status}}' => __('Status', 'fluent-cart'), |
| 373 |
'{{subscription.billing_interval}}' => __('Billing Interval', 'fluent-cart'), |
| 374 |
'{{subscription.recurring_amount}}' => __('Recurring Amount', 'fluent-cart'), |
| 375 |
'{{subscription.recurring_amount_formatted}}' => __('Recurring Amount (Formatted)', 'fluent-cart'), |
| 376 |
'{{subscription.payment_info}}' => __('Payment Info', 'fluent-cart'), |
| 377 |
'{{subscription.next_billing_date}}' => __('Next Billing Date', 'fluent-cart'), |
| 378 |
'{{subscription.bill_times}}' => __('Bill Times', 'fluent-cart'), |
| 379 |
'{{subscription.bill_count}}' => __('Bill Count', 'fluent-cart'), |
| 380 |
'{{subscription.trial_days}}' => __('Trial Days', 'fluent-cart'), |
| 381 |
'{{subscription.expire_at}}' => __('Expiration Date', 'fluent-cart'), |
| 382 |
], |
| 383 |
]; |
| 384 |
} |
| 385 |
|
| 386 |
public static function getButtons() |
| 387 |
{ |
| 388 |
$url = esc_url(site_url()); |
| 389 |
return [ |
| 390 |
'View Order' => '<a href="' . $url . '/wp-admin/admin.php?page=fluent-cart#/orders/{{order.id}}/view" style="background-color: green; color: #fff; padding: 10px 20px; text-decoration: none; border-radius: 5px;">View Order</a>' |
| 391 |
]; |
| 392 |
} |
| 393 |
} |
| 394 |
|