class-evf-field-address.php
1 year ago
class-evf-field-ai.php
1 year ago
class-evf-field-captcha.php
1 month ago
class-evf-field-checkbox.php
3 months ago
class-evf-field-color.php
1 month ago
class-evf-field-country.php
3 months ago
class-evf-field-credit-card.php
1 month ago
class-evf-field-date-time.php
1 month ago
class-evf-field-divider.php
2 years ago
class-evf-field-email.php
1 year ago
class-evf-field-file-upload.php
1 year ago
class-evf-field-first-name.php
1 year ago
class-evf-field-hcaptcha.php
4 months ago
class-evf-field-hidden.php
1 year ago
class-evf-field-html.php
9 months ago
class-evf-field-image-upload.php
1 year ago
class-evf-field-last-name.php
1 year ago
class-evf-field-likert.php
1 year ago
class-evf-field-lookup.php
1 month ago
class-evf-field-number.php
1 year ago
class-evf-field-password.php
1 month ago
class-evf-field-payment-authorize-net.php
1 month ago
class-evf-field-payment-checkbox.php
1 month ago
class-evf-field-payment-coupon.php
1 month ago
class-evf-field-payment-gateway-selector.php
1 month ago
class-evf-field-payment-quantity.php
1 month ago
class-evf-field-payment-radio.php
1 month ago
class-evf-field-payment-single.php
1 month ago
class-evf-field-payment-square.php
1 year ago
class-evf-field-payment-subscription-plan.php
1 month ago
class-evf-field-payment-subtotal.php
1 month ago
class-evf-field-payment-total.php
1 month ago
class-evf-field-phone.php
1 year ago
class-evf-field-privacy-policy.php
3 months ago
class-evf-field-private-note.php
1 year ago
class-evf-field-progress.php
1 month ago
class-evf-field-radio.php
3 months ago
class-evf-field-range-slider.php
1 month ago
class-evf-field-rating.php
3 months ago
class-evf-field-recaptcha.php
4 months ago
class-evf-field-repeater.php
1 month ago
class-evf-field-reset.php
1 month ago
class-evf-field-scale-rating.php
1 year ago
class-evf-field-select.php
1 year ago
class-evf-field-signature.php
1 month ago
class-evf-field-text.php
1 year ago
class-evf-field-textarea.php
1 year ago
class-evf-field-title.php
2 years ago
class-evf-field-turnstile.php
4 months ago
class-evf-field-url.php
1 year ago
class-evf-field-wysiwyg.php
3 months ago
class-evf-field-yes-no.php
1 year ago
payment-amount-helpers.php
1 month ago
class-evf-field-payment-subtotal.php
137 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Payment Subtotal field |
| 4 | * |
| 5 | * @package EverestForms\Fields |
| 6 | * @since 1.9.6 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | // Currency-aware amount helper so the preview matches the real Pro field. |
| 12 | require_once __DIR__ . '/payment-amount-helpers.php'; |
| 13 | |
| 14 | /** |
| 15 | * EVF_Field_Payment_Subtotal Class. |
| 16 | * |
| 17 | * Builder-scope (read-only) version shipped in the free plugin so the field can |
| 18 | * be shown LOCKED — with its real preview and readable settings — for the AI |
| 19 | * upsell. The full functional implementation (front-end display, validation, |
| 20 | * processing) lives in Everest Forms Pro, whose class loads in place of this one |
| 21 | * when the plugin is active (this file is only autoloaded when that class is not |
| 22 | * already defined). Keep `is_pro = true` so the field stays locked. |
| 23 | */ |
| 24 | class EVF_Field_Payment_Subtotal extends EVF_Form_Fields { |
| 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | $this->name = esc_html__( 'Subtotal', 'everest-forms' ); |
| 31 | $this->type = 'payment-subtotal'; |
| 32 | $this->icon = 'evf-icon evf-icon-subtotal'; |
| 33 | $this->order = 220; |
| 34 | $this->group = 'payment'; |
| 35 | $this->is_pro = true; |
| 36 | $this->links = array( |
| 37 | 'image_id' => '', |
| 38 | 'vedio_id' => 'PpRGYqBTeoI', |
| 39 | ); |
| 40 | $this->settings = array( |
| 41 | 'basic-options' => array( |
| 42 | 'field_options' => array( |
| 43 | 'label', |
| 44 | 'description', |
| 45 | 'map_field', |
| 46 | 'required', |
| 47 | 'required_field_message_setting', |
| 48 | 'required_field_message', |
| 49 | ), |
| 50 | ), |
| 51 | 'advanced-options' => array( |
| 52 | 'field_options' => array( |
| 53 | 'meta', |
| 54 | 'label_hide', |
| 55 | 'css', |
| 56 | ), |
| 57 | ), |
| 58 | ); |
| 59 | |
| 60 | parent::__construct(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Mapping the payment field with quantity. |
| 65 | * |
| 66 | * @param array $field Field data object. |
| 67 | */ |
| 68 | public function map_field( $field ) { |
| 69 | $form_id = isset( $_GET['form_id'] ) ? wp_unslash( absint( $_GET['form_id'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
| 70 | $form_obj = EVF()->form->get( $form_id ); |
| 71 | $form_data = ! empty( $form_obj->post_content ) ? evf_decode( $form_obj->post_content ) : ''; |
| 72 | $options = array(); |
| 73 | |
| 74 | if ( isset( $form_data['form_fields'] ) && is_array( $form_data['form_fields'] ) ) { |
| 75 | foreach ( $form_data['form_fields'] as $id => $form_field ) { |
| 76 | if ( isset( $form_field['enable_payment_slider'] ) && '1' === $form_field['enable_payment_slider'] ) { |
| 77 | if ( in_array( $form_field['type'], array( 'payment-single', 'payment-multiple', 'payment-checkbox', 'range-slider' ), true ) ) { |
| 78 | $options[ $form_field['id'] ] = $form_field['label']; |
| 79 | } |
| 80 | } else { |
| 81 | if ( in_array( $form_field['type'], array( 'payment-single', 'payment-multiple', 'payment-checkbox' ), true ) ) { |
| 82 | $options[ $form_field['id'] ] = $form_field['label']; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | $options = evf_parse_args( $options, array( '' => __( '---Select a Field---', 'everest-forms' ) ) ); |
| 89 | |
| 90 | // Input Mask. |
| 91 | $lbl = $this->field_element( |
| 92 | 'label', |
| 93 | $field, |
| 94 | array( |
| 95 | 'slug' => 'map_field', |
| 96 | 'value' => esc_html__( 'Calculate with this field', 'everest-forms' ), |
| 97 | 'tooltip' => esc_html__( 'Calculate subtoal value for this selected payment field.', 'everest-forms' ), |
| 98 | ), |
| 99 | false |
| 100 | ); |
| 101 | $fld = $this->field_element( |
| 102 | 'select', |
| 103 | $field, |
| 104 | array( |
| 105 | 'slug' => 'map_field', |
| 106 | 'value' => ! empty( $field['map_field'] ) ? esc_attr( $field['map_field'] ) : '', |
| 107 | 'options' => $options, |
| 108 | ), |
| 109 | false |
| 110 | ); |
| 111 | $this->field_element( |
| 112 | 'row', |
| 113 | $field, |
| 114 | array( |
| 115 | 'slug' => 'map_field', |
| 116 | 'content' => $lbl . $fld, |
| 117 | ) |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Field preview inside the builder (matches the Pro Subtotal field). |
| 123 | * |
| 124 | * @param array $field Field data and settings. |
| 125 | */ |
| 126 | public function field_preview( $field ) { |
| 127 | // Label. |
| 128 | $this->field_preview_option( 'label', $field ); |
| 129 | |
| 130 | // Primary field. |
| 131 | echo '<div>' . evf_format_amount( 0, true ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 132 | |
| 133 | // Description. |
| 134 | $this->field_preview_option( 'description', $field ); |
| 135 | } |
| 136 | } |
| 137 |