| 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> |