Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/d5beb46b3ccc42e20dc8c359a3286d63 to your computer and use it in GitHub Desktop.
Save xlplugins/d5beb46b3ccc42e20dc8c359a3286d63 to your computer and use it in GitHub Desktop.
Try to re render klarna paylater message on Single product page.
class FKWCS_Klarna_message_div {
public function __construct() {
add_action( 'woocommerce_after_template_part', [ $this, 'render_paylater' ] );
add_action( 'wp_footer', [ $this, 'render_paylater_message_div' ], 99 );
}
public function render_paylater( $template_name ) {
if ( ( $template_name === 'single-product/add-to-cart/variable.php' || $template_name === 'single-product/add-to-cart/simple.php' ) && is_product() ) {
echo "<div class='fkwcs_snippet_paylater_message' style='display: none;'>";
\FKWCS\Gateway\Stripe\PayLater_Helper::get_instance()->single_button_wrapper();
echo ' </div > ';
}
}
/**
* Render the Pay Later message div on single product pages.
*
* This function checks if the current page is a product page and then outputs
* a div that contains the Pay Later message and button.
*/
public function render_paylater_message_div() {
if ( ! is_product() ) {
return;
}
?>
<script>
(function ($) {
$(document).ready(function () {
let form_cart = $('form.cart');
// Check if the form_cart exists
if (form_cart.length > 0) {
let paylater_container_exist = form_cart.parent('div').find('.fkwcs_paylater_messaging');
if (paylater_container_exist.length === 2) {
return;
}
let message_div = $('.fkwcs_snippet_paylater_message');
if (paylater_container_exist.length === 1 && message_div.length == 1) {
message_div.show();
}
}
});
})(jQuery);
</script>
<?php
}
}
new FKWCS_Klarna_message_div();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment