Skip to content

Instantly share code, notes, and snippets.

@pavlo-bondarchuk
Created June 22, 2019 10:13
Show Gist options
  • Save pavlo-bondarchuk/844e3b9f5784f0e09a395502141445ce to your computer and use it in GitHub Desktop.
Save pavlo-bondarchuk/844e3b9f5784f0e09a395502141445ce to your computer and use it in GitHub Desktop.
popup on event adding_to_cart
//add_action('wp_footer', 'show_template');
add_action(
'wp_footer',
function() {
?>
<script>jQuery( function( $ ) {
// Цепляемся за событие adding_to_cart
$( document.body ).on( 'adding_to_cart', function( event, button ) {
// Выцепляем инициатора события (ссылка/кнопка)
var $btn = $( button[0] );
// Пытаемся найти в вёрстке название товара
var product_title = $btn.parents( 'li.product' ).find( '.woocommerce-loop-product__title' ).text();
if ( product_title ) {
// Формируем шаблон попапа
var tpl = '';
tpl += '<p style="font-weight: bold;text-transform: uppercase;">Товар добавлен в корзину <br><p>"' + product_title + '"</p></p>';
tpl += '<div>';
tpl += '<a class="button go_on" onclick="jQuery.unblockUI();">Продолжить</a>';
tpl += '<a href="/shop/cart/" class="button go_on alt">Оформить</a>';
tpl += '</div>';
// Выводим шаблон в модальное окно.
// Используем blockUI из WooCommerce
$.blockUI({
message: tpl,
timeout: 5000,
css: {
width: '300px',
border: 0,
padding: 30
}
} );
}
} );
} ); </script>
<?php
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment