PluginProbe
seQura / 4.3.0
seQura v4.3.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / templates / front / widget.php

widget.php in seQura 4.3.0, at templates/front/widget.php

57 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Widget template
4 *
5 * @package SeQura/WC
6 * @var array<string, string> $args The arguments. Must contain:
7 * - string 'product' The seQura payment method identifier.
8 * - string 'campaign' The seQura campaign identifier.
9 * - string 'dest' The CSS selector to place the widget.
10 * - string 'price' The CSS selector for the price.
11 * - string 'alt_price' The CSS selector for the alternative price.
12 * - string 'is_alt_price' The CSS selector to determine if the product has an alternative price.
13 * - string 'reg_amount' The registration amount.
14 * - string 'theme' The theme to use.
15 */
16
17 defined( 'WPINC' ) || die;
18
19 // Check if the variables are defined.
20 if ( ! isset(
21 $args['product'],
22 $args['dest'],
23 $args['theme'],
24 $args['reverse'],
25 $args['campaign'],
26 $args['price'],
27 $args['alt_price'],
28 $args['is_alt_price'],
29 $args['reg_amount']
30 ) ) {
31 return;
32 }
33 $price = strval( $args['price'] );
34 $is_price_numeric = preg_match( '/^[0-9]+(?:[.,][0-9]+)?$/', $price );
35 $in_place_widget_id = str_replace( '.', '', uniqid( 'sequra-widget-', true ) );
36 $in_place_widget_selector = '#' . $in_place_widget_id;
37 $dest = empty( $args['dest'] ) ? $in_place_widget_selector : strval( $args['dest'] );
38
39 //phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
40 if ( $is_price_numeric || empty( $args['dest'] ) ) : ?>
41 <div id="<?php echo esc_attr( $in_place_widget_id ); ?>" style="display: none;" aria-hidden="true"><?php echo $is_price_numeric ? esc_html( $price ) : ''; ?></div>
42 <?php endif; ?>
43 <script type='text/javascript'>
44 SequraWidgetFacade.widgets && SequraWidgetFacade.widgets.push({
45 product: <?php echo wp_json_encode( $args['product'] ); ?>,
46 dest: <?php echo wp_json_encode( $dest ); ?>,
47 theme: <?php echo wp_json_encode( $args['theme'] ); ?>,
48 reverse: <?php echo wp_json_encode( $args['reverse'] ); ?>,
49 campaign: <?php echo wp_json_encode( $args['campaign'] ); ?>,
50 priceSel: <?php echo wp_json_encode( $is_price_numeric ? $in_place_widget_selector : $price ); ?>,
51 variationPriceSel: <?php echo $is_price_numeric ? 'null' : wp_json_encode( $args['alt_price'] ); ?>,
52 isVariableSel: <?php echo $is_price_numeric ? 'null' : wp_json_encode( $args['is_alt_price'] ); ?>,
53 registrationAmount: <?php echo wp_json_encode( $args['reg_amount'] ); ?>,
54 minAmount: <?php echo $args['min_amount'] ? wp_json_encode( $args['min_amount'] ) : '0'; ?>,
55 maxAmount: <?php echo $args['max_amount'] ? wp_json_encode( $args['max_amount'] ) : 'null'; ?>
56 });
57 </script>