| @@ -12,15 +12,19 @@ | ||
| 12 | 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 | 13 | $is_payment_type_woocommerce = !empty($settings["better_payment_form_payment_source"]) && 'woocommerce' === $settings["better_payment_form_payment_source"] ? true : false; |
| 14 | 14 | $is_payment_type_fluentcart = !empty($settings["better_payment_form_payment_source"]) && 'fluentcart' === $settings["better_payment_form_payment_source"] ? true : false; |
| 15 | 15 | $is_payment_type_stripe = !empty($settings["better_payment_form_payment_source"]) && 'stripe' === $settings["better_payment_form_payment_source"] ? true : false; |
| 16 | -$is_payment_recurring = ! empty( $settings["better_payment_form_payment_type"] ) && 'recurring' === $settings["better_payment_form_payment_type"] ? 1 : 0; | |
| 17 | -$is_payment_split_payment = ! empty( $settings["better_payment_form_payment_type"] ) && 'split-payment' === $settings["better_payment_form_payment_type"] ? 1 : 0; | |
| 18 | -$payment_type_text = ! empty( $settings["better_payment_form_payment_type"] ) ? sanitize_text_field( $settings["better_payment_form_payment_type"] ) : 'One Time'; | |
| 19 | -$layout_put_amount_field_hide_show = ( $is_payment_recurring || $is_payment_split_payment ) ? 'is-hidden' : $layout_put_amount_field_hide_show; | |
| 20 | -$is_layout_for_woocommerce = ! empty( $settings["better_payment_form_layout"] ) && in_array( $settings["better_payment_form_layout"], ['layout-6-pro'] ) && ( empty( $settings["better_payment_form_layout_6_ecommerce_platform"] ) || 'woocommerce' === $settings["better_payment_form_layout_6_ecommerce_platform"] ) ? 1 : 0; | |
| 21 | -$is_layout_for_fluentcart = ! empty( $settings["better_payment_form_layout"] ) && 'layout-6-pro' === $settings["better_payment_form_layout"] && ! empty( $settings["better_payment_form_layout_6_ecommerce_platform"] ) && 'fluentcart' === $settings["better_payment_form_layout_6_ecommerce_platform"] ? 1 : 0; | |
| 22 | 16 | |
| 17 | +// Pro layouts 4-6 (payment type, eCommerce platform, layout 6's product list) are computed | |
| 18 | +// by Better Payment Pro in its own partials/layout-vars.php, which its templates include | |
| 19 | +// right after this file. These neutral defaults keep the names defined for those templates, | |
| 20 | +// and a free install never renders a Pro layout. | |
| 21 | +$is_payment_recurring = 0; | |
| 22 | +$is_payment_split_payment = 0; | |
| 23 | +$payment_type_text = 'One Time'; | |
| 24 | +$is_layout_for_woocommerce = 0; | |
| 25 | +$is_layout_for_fluentcart = 0; | |
| 26 | + | |
| 23 | 27 | if( !empty($_GET[ 'campaign_currency' ]) ) { |
| 24 | 28 | $layout_form_currency = sanitize_text_field( $_GET[ 'campaign_currency' ] ); |
| 25 | 29 | } else { |
| 26 | 30 | $layout_form_currency = !empty($settings["better_payment_form_currency"]) ? sanitize_text_field( $settings["better_payment_form_currency"] ) : ''; |
| @@ -29,9 +33,8 @@ | ||
| 29 | 33 | $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>'; |
| 30 | 34 | |
| 31 | 35 | $currency_alignment = ! empty ( $settings['better_payment_form_currency_alignment'] ) ? $settings['better_payment_form_currency_alignment'] : 'left'; |
| 32 | 36 | |
| 33 | -$product_details = []; | |
| 34 | 37 | $product_name = ''; |
| 35 | 38 | $product_permalink = ''; |
| 36 | 39 | $product_price = ''; |
| 37 | 40 | $payment_amount_field_exists = 0; |
| @@ -37,9 +40,9 @@ | ||
| 37 | 40 | $payment_amount_field_exists = 0; |
| 38 | 41 | $is_payment_amount_field_hidden = 0; |
| 39 | 42 | $valid_html_tags = wp_kses_allowed_html( 'post' ); |
| 40 | 43 | $sidebar_show = ! empty( $settings['better_payment_form_sidebar_show'] ) && 'yes' === $settings['better_payment_form_sidebar_show']; |
| 41 | -if ( $is_payment_type_woocommerce || $is_layout_for_woocommerce ) { | |
| 44 | +if ( $is_payment_type_woocommerce ) { | |
| 42 | 45 | if( |
| 43 | 46 | !empty($settings['better_payment_form_currency_use_woocommerce']) && 'yes' === $settings['better_payment_form_currency_use_woocommerce'] && |
| 44 | 47 | !empty($settings['better_payment_form_currency_woocommerce']) |
| 45 | 48 | ) { |
| @@ -47,116 +50,53 @@ | ||
| 47 | 50 | } |
| 48 | 51 | |
| 49 | 52 | //Fetch product data using product ID |
| 50 | 53 | $layout_form_woocommerce_product_id = !empty($settings["better_payment_form_woocommerce_product_id"]) ? intval($settings["better_payment_form_woocommerce_product_id"]) : 0; |
| 51 | - $layout_form_woocommerce_product_ids = !empty($settings["better_payment_form_woocommerce_product_ids"]) ? $settings["better_payment_form_woocommerce_product_ids"] : [0]; | |
| 52 | - $product_price_total = 0; | |
| 53 | 54 | |
| 54 | 55 | if (function_exists('wc_get_product')) { |
| 55 | - if ( $is_layout_for_woocommerce ) { | |
| 56 | - $product_details = []; | |
| 56 | + $bp_woocommerce_product = wc_get_product($layout_form_woocommerce_product_id); | |
| 57 | + $product = $bp_woocommerce_product; | |
| 57 | 58 | |
| 58 | - foreach( $layout_form_woocommerce_product_ids as $single_product_id ){ | |
| 59 | - $bp_woocommerce_product = wc_get_product($single_product_id); | |
| 60 | - $product = $bp_woocommerce_product; | |
| 61 | - | |
| 62 | - if ($product) { | |
| 63 | - $product_details[$single_product_id]['product_name'] = $product->get_name(); | |
| 64 | - $product_details[$single_product_id]['product_permalink'] = get_permalink($product->get_id()); | |
| 65 | - $product_details[$single_product_id]['product_price'] = $product->get_price(); | |
| 66 | - $product_details[$single_product_id]['product_image_src_array'] = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' ); | |
| 67 | - | |
| 68 | - $product_image_src_array = $product_details[$single_product_id]['product_image_src_array']; | |
| 69 | - $product_details[$single_product_id]['product_image_src'] = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; | |
| 70 | - | |
| 71 | - $product_price_total += floatval( $product_details[$single_product_id]['product_price'] ); | |
| 72 | - } | |
| 73 | - } | |
| 74 | - } else { | |
| 75 | - $bp_woocommerce_product = wc_get_product($layout_form_woocommerce_product_id); | |
| 76 | - $product = $bp_woocommerce_product; | |
| 77 | - | |
| 78 | - if ($product) { | |
| 79 | - $product_name = $product->get_name(); | |
| 80 | - $product_permalink = get_permalink($product->get_id()); | |
| 81 | - $product_price = $product->get_price(); | |
| 82 | - $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' ); | |
| 83 | - $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; | |
| 84 | - } | |
| 59 | + if ($product) { | |
| 60 | + $product_name = $product->get_name(); | |
| 61 | + $product_permalink = get_permalink($product->get_id()); | |
| 62 | + $product_price = $product->get_price(); | |
| 63 | + $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' ); | |
| 64 | + $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; | |
| 85 | 65 | } |
| 86 | 66 | } |
| 87 | 67 | } |
| 88 | 68 | |
| 89 | -if ( $is_payment_type_fluentcart || $is_layout_for_fluentcart ) { | |
| 69 | +if ( $is_payment_type_fluentcart ) { | |
| 90 | 70 | $layout_form_fluentcart_product_id = !empty($settings["better_payment_form_fluentcart_product_id"]) ? intval($settings["better_payment_form_fluentcart_product_id"]) : 0; |
| 91 | - $layout_form_fluentcart_product_ids = !empty($settings["better_payment_form_fluentcart_product_ids"]) ? $settings["better_payment_form_fluentcart_product_ids"] : [0]; | |
| 92 | - $product_price_total = 0; | |
| 93 | 71 | |
| 94 | 72 | if (function_exists('fluentCart') && class_exists( '\FluentCart\App\Models\Product' ) ) { |
| 95 | - if ( $is_layout_for_fluentcart ) { | |
| 96 | - $product_details = []; | |
| 73 | + try { | |
| 74 | + $fluentcart_product = \FluentCart\App\Models\Product::query() | |
| 75 | + ->with(['detail', 'variants']) | |
| 76 | + ->find($layout_form_fluentcart_product_id); | |
| 97 | 77 | |
| 98 | - foreach( $layout_form_fluentcart_product_ids as $single_product_id ){ | |
| 99 | - try { | |
| 100 | - $fluentcart_product = \FluentCart\App\Models\Product::query() | |
| 101 | - ->with(['detail', 'variants']) | |
| 102 | - ->find($single_product_id); | |
| 78 | + if ($fluentcart_product) { | |
| 79 | + $product_name = $fluentcart_product->post_title; | |
| 80 | + $product_permalink = get_permalink($fluentcart_product->ID); | |
| 103 | 81 | |
| 104 | - if ($fluentcart_product) { | |
| 105 | - $product_details[$single_product_id]['product_name'] = $fluentcart_product->post_title; | |
| 106 | - $product_details[$single_product_id]['product_permalink'] = get_permalink($fluentcart_product->ID); | |
| 82 | + $fluentcart_price = 0; | |
| 83 | + if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) { | |
| 84 | + $fluentcart_price = $fluentcart_product->variants[0]->item_price; | |
| 85 | + } elseif (!empty($fluentcart_product->detail)) { | |
| 86 | + $fluentcart_price = $fluentcart_product->detail->min_price; | |
| 87 | + } | |
| 107 | 88 | |
| 108 | - $fluentcart_price = 0; | |
| 109 | - if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) { | |
| 110 | - $fluentcart_price = $fluentcart_product->variants[0]->item_price; | |
| 111 | - } elseif (!empty($fluentcart_product->detail)) { | |
| 112 | - $fluentcart_price = $fluentcart_product->detail->min_price; | |
| 113 | - } | |
| 114 | - | |
| 115 | - if ( ! empty( $fluentcart_price ) ) { | |
| 116 | - $fluentcart_price = floatval( $fluentcart_price / 100 ); | |
| 117 | - } | |
| 118 | - | |
| 119 | - $product_details[$single_product_id]['product_price'] = $fluentcart_price; | |
| 120 | - $product_details[$single_product_id]['product_image_src_array'] = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' ); | |
| 121 | - | |
| 122 | - $product_image_src_array = $product_details[$single_product_id]['product_image_src_array']; | |
| 123 | - $product_details[$single_product_id]['product_image_src'] = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; | |
| 124 | - | |
| 125 | - $product_price_total += floatval( $product_details[$single_product_id]['product_price'] ); | |
| 126 | - } | |
| 127 | - } catch (Exception $e) { | |
| 128 | - // Handle exception silently | |
| 89 | + if ( ! empty( $fluentcart_price ) ) { | |
| 90 | + $fluentcart_price = floatval( $fluentcart_price / 100 ); | |
| 129 | 91 | } |
| 130 | - } | |
| 131 | - } else { | |
| 132 | - try { | |
| 133 | - $fluentcart_product = \FluentCart\App\Models\Product::query() | |
| 134 | - ->with(['detail', 'variants']) | |
| 135 | - ->find($layout_form_fluentcart_product_id); | |
| 136 | 92 | |
| 137 | - if ($fluentcart_product) { | |
| 138 | - $product_name = $fluentcart_product->post_title; | |
| 139 | - $product_permalink = get_permalink($fluentcart_product->ID); | |
| 140 | - | |
| 141 | - $fluentcart_price = 0; | |
| 142 | - if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) { | |
| 143 | - $fluentcart_price = $fluentcart_product->variants[0]->item_price; | |
| 144 | - } elseif (!empty($fluentcart_product->detail)) { | |
| 145 | - $fluentcart_price = $fluentcart_product->detail->min_price; | |
| 146 | - } | |
| 147 | - | |
| 148 | - if ( ! empty( $fluentcart_price ) ) { | |
| 149 | - $fluentcart_price = floatval( $fluentcart_price / 100 ); | |
| 150 | - } | |
| 151 | - | |
| 152 | - $product_price = $fluentcart_price; | |
| 153 | - $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' ); | |
| 154 | - $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; | |
| 155 | - } | |
| 156 | - } catch (Exception $e) { | |
| 157 | - // Handle exception silently | |
| 93 | + $product_price = $fluentcart_price; | |
| 94 | + $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' ); | |
| 95 | + $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; | |
| 158 | 96 | } |
| 97 | + } catch (Exception $e) { | |
| 98 | + // Handle exception silently | |
| 159 | 99 | } |
| 160 | 100 | } |
| 161 | 101 | } |
| 162 | 102 | |