PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.13
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.13
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 / classes / class-wpfnl-testimonial-actions.php

class-wpfnl-testimonial-actions.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.13, at classes/class-wpfnl-testimonial-actions.php

153 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This class is responsible for rendering the testimonial section on frontend checkout pages.
4 *
5 * @package WPFunnels
6 */
7 namespace WPFunnels\Classes\TestimonialActions;
8
9 use WPFunnels\Wpfnl_functions;
10
11 class Wpfnl_Testimonial_Action {
12
13 /**
14 * Testimonial config for the current checkout step.
15 *
16 * @var array
17 */
18 protected $config = array();
19
20 /**
21 * Current checkout step ID.
22 *
23 * @var int
24 */
25 protected $checkout_id = 0;
26
27 public function __construct() {
28 add_action( 'wpfunnels/before_checkout_form', array( $this, 'load_actions' ), 20, 1 );
29 add_action( 'wpfunnels/elementor_render_testimonial', array( $this, 'load_elementor_actions' ), 9999, 1 );
30 }
31
32
33 /**
34 * Load action hooks for testimonial render (all builder paths).
35 *
36 * @param int $checkout_id
37 *
38 * @return void
39 */
40 public function load_actions( $checkout_id ) {
41 if ( ! function_exists( 'is_plugin_active' ) ) {
42 require_once ABSPATH . '/wp-admin/includes/plugin.php';
43 }
44
45 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
46 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
47 return;
48 }
49 }
50
51 $this->checkout_id = (int) $checkout_id;
52 $this->config = $this->get_config( $this->checkout_id );
53
54 $this->trigger_testimonial_actions();
55 }
56
57
58 /**
59 * Load action hooks for Elementor editor/preview.
60 *
61 * @param int $checkout_id
62 *
63 * @return void
64 */
65 public function load_elementor_actions( $checkout_id ) {
66 $this->checkout_id = (int) $checkout_id;
67 $this->config = $this->get_config( $this->checkout_id );
68 $this->trigger_testimonial_actions();
69 }
70
71
72 /**
73 * Get and validate testimonial config from post meta.
74 *
75 * @param int $checkout_id
76 *
77 * @return array
78 */
79 private function get_config( $checkout_id ) {
80 $raw = get_post_meta( $checkout_id, 'wpf_checkout_testimonial', true );
81
82 if ( ! is_array( $raw ) ) {
83 $raw = array();
84 }
85
86 $defaults = array(
87 'enabled' => false,
88 'layout' => 'layout-1',
89 'position' => 'after_bump',
90 'testimonial' => array(
91 'text' => '',
92 'author' => '',
93 'rating' => 5,
94 ),
95 'guarantee' => array(
96 'headline' => '',
97 'text' => '',
98 'days' => 30,
99 'image' => array( 'id' => 0, 'url' => '' ),
100 ),
101 'benefits' => array(
102 'title' => 'Here\'s what you get',
103 'items' => array(),
104 ),
105 );
106
107 return wp_parse_args( $raw, $defaults );
108 }
109
110
111 /**
112 * Register WooCommerce/WPFunnels action hooks based on the configured position.
113 *
114 * @return void
115 */
116 private function trigger_testimonial_actions() {
117 if ( empty( $this->config['enabled'] ) ) {
118 return;
119 }
120
121 $position = isset( $this->config['position'] ) ? $this->config['position'] : 'after_bump';
122
123 if ( 'after_bump' === $position ) {
124 add_action( 'wpfunnels/after_order_total', array( $this, 'render' ), 20 );
125 } elseif ( 'before_bump' === $position ) {
126 add_action( 'woocommerce_review_order_before_cart_contents', array( $this, 'render' ), 20 );
127 } elseif ( 'above_form' === $position ) {
128 add_action( 'woocommerce_before_checkout_form', array( $this, 'render' ), 20 );
129 } elseif ( 'below_form' === $position ) {
130 add_action( 'woocommerce_review_order_after_payment', array( $this, 'render' ), 20 );
131 }
132 }
133
134
135 /**
136 * Render the testimonial section HTML.
137 *
138 * @return void
139 */
140 public function render() {
141 if ( empty( $this->config['enabled'] ) ) {
142 return;
143 }
144
145 $layout = sanitize_key( isset( $this->config['layout'] ) ? $this->config['layout'] : 'layout-1' );
146 $template = WPFNL_DIR . 'public/modules/checkout/testimonial/' . $layout . '.php';
147
148 if ( file_exists( $template ) ) {
149 load_template( $template, false, $this->config );
150 }
151 }
152 }
153