PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.9
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.9
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / widgets / oxygen / elements / class-offer-button.php

class-offer-button.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.9, at includes/core/widgets/oxygen/elements/class-offer-button.php

183 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPFunnels\Widgets\Oxygen\Elements;
3
4 use WPFunnels\Wpfnl_functions;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly
8 }
9
10 /**
11 * Offer Button Element for Oxygen Builder
12 *
13 * @since 3.0.0
14 */
15 class OfferButton extends \OxyEl {
16
17 public $css_added = false;
18
19 /**
20 * Element name
21 */
22 function name() {
23 return __( 'Offer Button', 'wpfnl' );
24 }
25
26 /**
27 * Element slug
28 */
29 function slug() {
30 return 'wpfnl_offer_button';
31 }
32
33 /**
34 * Element icon
35 */
36 function icon() {
37 return plugin_dir_url( __FILE__ ) . 'icon.svg';
38 }
39
40 /**
41 * Button place
42 */
43 function button_place() {
44 return 'wpfunnels::helpers';
45 }
46
47 /**
48 * Register controls
49 */
50 function controls() {
51 // Settings Section
52 $this->addOptionControl(
53 array(
54 'type' => 'buttons-list',
55 'name' => __( 'Button Action', 'wpfnl' ),
56 'slug' => 'offer_action',
57 'value' => array(
58 'accept' => __( 'Accept Offer', 'wpfnl' ),
59 'reject' => __( 'Reject Offer', 'wpfnl' ),
60 ),
61 'default' => 'accept',
62 )
63 )->rebuildElementOnChange();
64
65 $this->addOptionControl(
66 array(
67 'type' => 'textfield',
68 'name' => __( 'Button Text', 'wpfnl' ),
69 'slug' => 'button_text',
70 'default' => __( 'Yes, Add to My Order!', 'wpfnl' ),
71 )
72 )->rebuildElementOnChange();
73
74 $this->addOptionControl(
75 array(
76 'type' => 'buttons-list',
77 'name' => __( 'Show Product Price', 'wpfnl' ),
78 'slug' => 'show_product_price',
79 'value' => array(
80 'yes' => __( 'Yes', 'wpfnl' ),
81 'no' => __( 'No', 'wpfnl' ),
82 ),
83 'default' => 'no',
84 'condition' => 'offer_action=accept',
85 )
86 )->rebuildElementOnChange();
87
88 $this->addOptionControl(
89 array(
90 'type' => 'buttons-list',
91 'name' => __( 'Button Alignment', 'wpfnl' ),
92 'slug' => 'button_alignment',
93 'value' => array(
94 'left' => __( 'Left', 'wpfnl' ),
95 'center' => __( 'Center', 'wpfnl' ),
96 'right' => __( 'Right', 'wpfnl' ),
97 ),
98 'default' => 'left',
99 )
100 )->rebuildElementOnChange();
101 }
102
103 /**
104 * Render element
105 */
106 function render( $options, $defaults, $content ) {
107 $offer_action = isset( $options['offer_action'] ) ? $options['offer_action'] : 'accept';
108 $button_text = isset( $options['button_text'] ) ? $options['button_text'] : __( 'Yes, Add to My Order!', 'wpfnl' );
109 $show_price = isset( $options['show_product_price'] ) ? $options['show_product_price'] : 'no';
110 $button_align = isset( $options['button_alignment'] ) ? $options['button_alignment'] : 'left';
111
112 // Get offer button type from settings or URL
113 $offer_button_type = isset( $options['offer_type'] ) ? $options['offer_type'] : 'upsell';
114
115 // Get product data
116 $response = \WPFunnels\Wpfnl_functions::get_product_data_for_widget( get_the_ID() );
117 $offer_product = isset($response['offer_product']) && $response['offer_product'] ? $response['offer_product'] : '';
118 $get_product_type = isset($response['get_product_type']) && $response['get_product_type'] ? $response['get_product_type'] : '';
119 ?>
120 <div class="wp-block-wpfnl-offer-btn-<?php echo esc_attr( $button_align ); ?>">
121 <div class="wpfnl-offerbtn-wrapper" id="wpfnl-offerbtn-wrapper">
122 <?php
123 if( ('variable' === $get_product_type || 'variable-subscription' === $get_product_type) && 'accept' === $offer_action ) {
124 echo '<div class="has-variation-product">';
125 echo '<div class="wpfnl-product-variation">';
126 if( 'yes' === $show_price ){
127 echo '<span class="offer-btn-loader"></span>';
128 }
129 $post_id = get_the_ID();
130 echo do_shortcode( '[wpf_variable_offer post_id="'.$post_id.'"]' );
131 echo '</div>';
132 }
133 ?>
134
135 <div class="wpfnl-offerbtn-and-price-wrapper">
136 <?php if ( $show_price === 'yes' && $offer_action === 'accept' ) : ?>
137 <span class="wpfnl-offer-product-price" id="wpfnl-offer-product-price">
138 <?php
139 if( ( 'variable' !== $get_product_type && 'variable-subscription' !== $get_product_type ) && 'accept' === $offer_action ){
140 $step_id = get_the_ID();
141 $step_type = get_post_meta( $step_id, '_step_type', true );
142 $products = get_post_meta( $step_id, '_wpfnl_' . $step_type . '_products', true );
143
144 if ( ! empty( $products ) && is_array( $products ) ) {
145 $product_id = isset( $products[0]['id'] ) ? $products[0]['id'] : 0;
146 if ( $product_id ) {
147 $product = wc_get_product( $product_id );
148 if ( $product ) {
149 echo $product->get_price_html();
150 }
151 }
152 }
153 }
154 ?>
155 </span>
156 <?php endif; ?>
157
158 <a href="#"
159 class="wpfunnels-oxygen-element wpfunnels_offer_button"
160 id="wpfunnels_<?php echo esc_attr( $offer_button_type ); ?>_<?php echo esc_attr( $offer_action ); ?>"
161 data-offertype="<?php echo esc_attr( $offer_button_type ); ?>">
162 <?php echo esc_html( $button_text ); ?>
163 </a>
164 </div>
165
166 <?php
167 if( ( 'variable' === $get_product_type || 'variable-subscription' === $get_product_type ) && 'accept' === $offer_action ) {
168 echo '</div>';
169 }
170 ?>
171 </div>
172 </div>
173 <?php
174
175 // Fire after offer button hook
176 if ( $offer_action !== 'reject' && \WPFunnels\Wpfnl_functions::is_wc_active() ) {
177 do_action( 'wpfunnels/after_offer_button' );
178 }
179 }
180 }
181
182 new OfferButton();
183