PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.0
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / includes / Admin / views / partials / layout-vars.php

layout-vars.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.4.0, at includes/Admin/views/partials/layout-vars.php

164 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $bp_helper_obj = new Better_Payment\Lite\Classes\Helper();
3 $layout_action = !empty($extraDatas['action']) ? $extraDatas['action'] : '';
4 $layout_setting_meta = !empty($extraDatas['setting_meta']) ? $extraDatas['setting_meta'] : '';
5 $layout_dynamic_payment_hide_show = !empty($settings["better_payment_form_payment_source"]) && !in_array($settings["better_payment_form_payment_source"], ['woocommerce', 'fluentcart']) ? 'is-hidden' : '';
6 $layout_put_amount_field_hide_show = !empty($settings["better_payment_form_payment_source"]) && in_array($settings["better_payment_form_payment_source"], ['woocommerce', 'fluentcart']) ? 'is-hidden' : '';
7 $layout_form_content_offset_class = !empty($settings["better_payment_form_payment_source"]) && !in_array($settings["better_payment_form_payment_source"], ['woocommerce', 'fluentcart']) ? '' : ''; //is-offset-2
8
9 $layout_form_transaction_details_heading = !empty($settings["better_payment_form_transaction_details_heading"]) ? $settings["better_payment_form_transaction_details_heading"] : '';
10 $layout_form_transaction_details_sub_heading = !empty($settings["better_payment_form_transaction_details_sub_heading"]) ? $settings["better_payment_form_transaction_details_sub_heading"] : '';
11 $layout_form_transaction_details_product_title = !empty($settings["better_payment_form_transaction_details_product_title"]) ? $settings["better_payment_form_transaction_details_product_title"] : '';
12 $layout_form_transaction_details_amount_text = !empty($settings["better_payment_form_transaction_details_amount_text"]) ? $settings["better_payment_form_transaction_details_amount_text"] : '';
13 $is_payment_type_woocommerce = !empty($settings["better_payment_form_payment_source"]) && 'woocommerce' === $settings["better_payment_form_payment_source"] ? true : false;
14 $is_payment_type_fluentcart = !empty($settings["better_payment_form_payment_source"]) && 'fluentcart' === $settings["better_payment_form_payment_source"] ? true : false;
15 $is_payment_type_stripe = !empty($settings["better_payment_form_payment_source"]) && 'stripe' === $settings["better_payment_form_payment_source"] ? true : false;
16
17 // Pro layouts 4-6: the payment type (layouts 4 and 5) and eCommerce platform (layout 6).
18 // Transitional copy for Better Payment Pro <= 1.4.3 (Classes\ProPaymentFormLayouts, slug
19 // `elementor_pro_layout_rendering`): a current Pro computes these in its own
20 // partials/layout-vars.php, which its templates include right after this file, and a free
21 // install never renders a Pro layout. The values below are neutral defaults otherwise.
22 // Delete this block, every `$bp_lite_renders_pro_layout` check below and the matching
23 // check in layout-repeater-vars.php together with the copy.
24 $is_payment_recurring = 0;
25 $is_payment_split_payment = 0;
26 $payment_type_text = 'One Time';
27 $is_layout_for_woocommerce = 0;
28 $is_layout_for_fluentcart = 0;
29 $bp_lite_renders_pro_layout = \Better_Payment\Lite\Classes\ProPaymentFormLayouts::lite_copy_applies();
30
31 if ( $bp_lite_renders_pro_layout ) {
32 $bp_pro_layout_vars = \Better_Payment\Lite\Classes\ProPaymentFormLayouts::layout_vars( $settings );
33 $is_payment_recurring = $bp_pro_layout_vars['is_payment_recurring'];
34 $is_payment_split_payment = $bp_pro_layout_vars['is_payment_split_payment'];
35 $payment_type_text = $bp_pro_layout_vars['payment_type_text'];
36 $layout_put_amount_field_hide_show = ( $is_payment_recurring || $is_payment_split_payment ) ? 'is-hidden' : $layout_put_amount_field_hide_show;
37 $is_layout_for_woocommerce = $bp_pro_layout_vars['is_layout_for_woocommerce'];
38 $is_layout_for_fluentcart = $bp_pro_layout_vars['is_layout_for_fluentcart'];
39 $product_details = [];
40 }
41
42 if( !empty($_GET[ 'campaign_currency' ]) ) {
43 $layout_form_currency = sanitize_text_field( $_GET[ 'campaign_currency' ] );
44 } else {
45 $layout_form_currency = !empty($settings["better_payment_form_currency"]) ? sanitize_text_field( $settings["better_payment_form_currency"] ) : '';
46 }
47
48 $layout_form_currency_symbol = $layout_form_currency ? $bp_helper_obj->get_currency_symbol(esc_html($layout_form_currency)) : '<i class="bp-icon bp-logo-2"></i>';
49
50 $currency_alignment = ! empty ( $settings['better_payment_form_currency_alignment'] ) ? $settings['better_payment_form_currency_alignment'] : 'left';
51
52 $product_name = '';
53 $product_permalink = '';
54 $product_price = '';
55 $payment_amount_field_exists = 0;
56 $is_payment_amount_field_hidden = 0;
57 $valid_html_tags = wp_kses_allowed_html( 'post' );
58 $sidebar_show = ! empty( $settings['better_payment_form_sidebar_show'] ) && 'yes' === $settings['better_payment_form_sidebar_show'];
59 if ( $is_payment_type_woocommerce || $is_layout_for_woocommerce ) {
60 if(
61 !empty($settings['better_payment_form_currency_use_woocommerce']) && 'yes' === $settings['better_payment_form_currency_use_woocommerce'] &&
62 !empty($settings['better_payment_form_currency_woocommerce'])
63 ) {
64 $layout_form_currency_symbol = $bp_helper_obj->get_currency_symbol( esc_html($settings['better_payment_form_currency_woocommerce']) );
65 }
66
67 //Fetch product data using product ID
68 $layout_form_woocommerce_product_id = !empty($settings["better_payment_form_woocommerce_product_id"]) ? intval($settings["better_payment_form_woocommerce_product_id"]) : 0;
69
70 if ( $bp_lite_renders_pro_layout ) {
71 $layout_form_woocommerce_product_ids = !empty($settings["better_payment_form_woocommerce_product_ids"]) ? $settings["better_payment_form_woocommerce_product_ids"] : [0];
72 $product_price_total = 0;
73 }
74
75 if (function_exists('wc_get_product')) {
76 if ( $is_layout_for_woocommerce ) {
77 // Layout 6 (Pro). Pro builds this list in its own partial once it declares
78 // `layout_6_product_details`.
79 if ( \Better_Payment\Lite\Classes\ProCompatibility::lite_copy_applies( \Better_Payment\Lite\Classes\ProLayoutProducts::FEATURE ) ) {
80 $layout_6_products = \Better_Payment\Lite\Classes\ProLayoutProducts::woocommerce( $layout_form_woocommerce_product_ids );
81 $product_details = $layout_6_products['details'];
82 $product_price_total = $layout_6_products['total'];
83 }
84 } else {
85 $bp_woocommerce_product = wc_get_product($layout_form_woocommerce_product_id);
86 $product = $bp_woocommerce_product;
87
88 if ($product) {
89 $product_name = $product->get_name();
90 $product_permalink = get_permalink($product->get_id());
91 $product_price = $product->get_price();
92 $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' );
93 $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : '';
94 }
95 }
96 }
97 }
98
99 if ( $is_payment_type_fluentcart || $is_layout_for_fluentcart ) {
100 $layout_form_fluentcart_product_id = !empty($settings["better_payment_form_fluentcart_product_id"]) ? intval($settings["better_payment_form_fluentcart_product_id"]) : 0;
101
102 if ( $bp_lite_renders_pro_layout ) {
103 $layout_form_fluentcart_product_ids = !empty($settings["better_payment_form_fluentcart_product_ids"]) ? $settings["better_payment_form_fluentcart_product_ids"] : [0];
104 $product_price_total = 0;
105 }
106
107 if (function_exists('fluentCart') && class_exists( '\FluentCart\App\Models\Product' ) ) {
108 if ( $is_layout_for_fluentcart ) {
109 // Layout 6 (Pro). Pro builds this list in its own partial once it declares
110 // `layout_6_product_details`.
111 if ( \Better_Payment\Lite\Classes\ProCompatibility::lite_copy_applies( \Better_Payment\Lite\Classes\ProLayoutProducts::FEATURE ) ) {
112 $layout_6_products = \Better_Payment\Lite\Classes\ProLayoutProducts::fluentcart( $layout_form_fluentcart_product_ids );
113 $product_details = $layout_6_products['details'];
114 $product_price_total = $layout_6_products['total'];
115 }
116 } else {
117 try {
118 $fluentcart_product = \FluentCart\App\Models\Product::query()
119 ->with(['detail', 'variants'])
120 ->find($layout_form_fluentcart_product_id);
121
122 if ($fluentcart_product) {
123 $product_name = $fluentcart_product->post_title;
124 $product_permalink = get_permalink($fluentcart_product->ID);
125
126 $fluentcart_price = 0;
127 if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) {
128 $fluentcart_price = $fluentcart_product->variants[0]->item_price;
129 } elseif (!empty($fluentcart_product->detail)) {
130 $fluentcart_price = $fluentcart_product->detail->min_price;
131 }
132
133 if ( ! empty( $fluentcart_price ) ) {
134 $fluentcart_price = floatval( $fluentcart_price / 100 );
135 }
136
137 $product_price = $fluentcart_price;
138 $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' );
139 $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : '';
140 }
141 } catch (Exception $e) {
142 // Handle exception silently
143 }
144 }
145 }
146 }
147
148 $layout_form_currency_left = 'left' === $currency_alignment ? $layout_form_currency_symbol : '';
149 $layout_form_currency_right = 'right' === $currency_alignment ? $layout_form_currency_symbol : '' ;
150
151 $stripe_public_key = 'yes' === sanitize_text_field( $settings[ 'better_payment_stripe_live_mode' ] ) ? sanitize_text_field( $settings[ 'better_payment_stripe_public_key_live' ] ) : sanitize_text_field( $settings[ 'better_payment_stripe_public_key' ] );
152 $stripe_secret_key = 'yes' === sanitize_text_field( $settings[ 'better_payment_stripe_live_mode' ] ) ? sanitize_text_field( $settings[ 'better_payment_stripe_secret_key_live' ] ) : sanitize_text_field( $settings[ 'better_payment_stripe_secret_key' ] );
153 $amount_quantity_text = ! empty( $settings['better_payment_show_amount_quantity_text'] ) ? $settings['better_payment_show_amount_quantity_text'] : 'Amount Quantity';
154
155 if ( $is_payment_type_stripe ) {
156 $payment_source_stripe_price_id = ! empty( $settings['better_payment_form_payment_source_stripe_price_id'] ) ? sanitize_text_field( $settings['better_payment_form_payment_source_stripe_price_id'] ) : '';
157
158 $stripe_price_details = $bp_helper_obj->get_stripe_price_details( $payment_source_stripe_price_id, $stripe_secret_key );
159
160 if ( ! empty( $stripe_price_details ) ) {
161 $product_price = ! empty( $stripe_price_details['unit_amount'] ) ? floatval( $stripe_price_details['unit_amount'] ) / 100 : '';
162 }
163 }
164