| 1 |
<?php |
| 2 |
/** |
| 3 |
* Part payment teaser template. |
| 4 |
* |
| 5 |
* @package woocommerce-sequra |
| 6 |
*/ |
| 7 |
|
| 8 |
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable |
| 9 |
?> |
| 10 |
<script type='text/javascript'> |
| 11 |
/*Customize if needed*/ |
| 12 |
VARIATION_PRICE_SEL = '.woocommerce-variation-price .price>.amount,.woocommerce-variation-price .price ins .amount,.woocommerce-variation-price .price .amount'; |
| 13 |
|
| 14 |
/*********************/ |
| 15 |
|
| 16 |
function displaySequra<?php echo esc_js( $product ); ?>Teaser(the_price_container, sq_product, campaign, theme) { |
| 17 |
var dest = '#sequra_partpayment_teaser_default_container'; |
| 18 |
if (jQuery('.woocommerce-variation-price').length) { |
| 19 |
dest = '.woocommerce-variation-price'; |
| 20 |
the_price_container = VARIATION_PRICE_SEL; |
| 21 |
} |
| 22 |
|
| 23 |
<?php if ( isset( $atts['dest'] ) && '' !== trim( $atts['dest'] ) ) { ?> |
| 24 |
var custom_dest = '<?php echo esc_js( $atts['dest'] ); ?>'.replace(/\>\;/g, ">"); |
| 25 |
if (jQuery(custom_dest).is(':visible')) { |
| 26 |
dest = custom_dest; |
| 27 |
} |
| 28 |
<?php } ?> |
| 29 |
SequraHelper.waitForElement(the_price_container).then(function () { |
| 30 |
SequraHelper.waitForElement(dest).then(function () { |
| 31 |
SequraHelper.drawPromotionWidget(the_price_container, dest, sq_product, theme, 0, campaign, <?php echo esc_js( $registration_amount ); ?>); |
| 32 |
Sequra.onLoad(function () { |
| 33 |
Sequra.refreshComponents(); |
| 34 |
}); |
| 35 |
}); |
| 36 |
}); |
| 37 |
} |
| 38 |
|
| 39 |
function updateSequra<?php echo esc_js( $product ); ?>Teaser(e) { |
| 40 |
var the_price_container = '<?php echo esc_js( $price_container ); ?>'.replace(/\>\;/g, ">"); |
| 41 |
if (e.type == 'show_variation' && jQuery(VARIATION_PRICE_SEL).length) { |
| 42 |
the_price_container = VARIATION_PRICE_SEL; |
| 43 |
} |
| 44 |
var price_in_cents = SequraHelper.selectorToCents(the_price_container); |
| 45 |
jQuery('[data-product=<?php echo esc_js( $product ); ?>]').attr('data-amount', price_in_cents); |
| 46 |
Sequra.onLoad(function () { |
| 47 |
Sequra.refreshComponents(); |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
document.addEventListener("DOMContentLoaded", function () { |
| 52 |
displaySequra<?php echo esc_js( $product ); ?>Teaser( |
| 53 |
'<?php echo esc_js( $price_container ); ?>'.replace(/\>\;/g, ">"), |
| 54 |
'<?php echo esc_js( $product ); ?>', |
| 55 |
'<?php echo esc_js( $campaign ); ?>', |
| 56 |
'<?php echo esc_js( $theme ); ?>'.replace(/\"\;/g, "\"") |
| 57 |
); |
| 58 |
jQuery('.variations_form') |
| 59 |
.on('hide_variation', updateSequra<?php echo esc_js( $product ); ?>Teaser) |
| 60 |
.on('show_variation', updateSequra<?php echo esc_js( $product ); ?>Teaser); |
| 61 |
}); |
| 62 |
</script> |
| 63 |
|