Всплывающее уведомление при добавление товаров
У меня готовый сайт на WordPress хочется чтобы при добавление товара в корзину выходило всплывающее уведомление что: "Товар добавлен!"
У меня готовый сайт на WordPress хочется чтобы при добавление товара в корзину выходило всплывающее уведомление что: "Товар добавлен!"
Вот так можно это делать
add_action( 'wp_footer', function () { ?> <script> jQuery( function( $ ) { $( document.body ).on( 'adding_to_cart', function( event, button ) { // Пытаемся найти в вёрстке название товара var product_title = $btn.parents( 'li.product' ).find( '.woocommerce-loop-product__title' ).text(); if ( product_title ) { var tpl = ''; tpl += '<p>Товар "' + product_title + '" добавлен в корзину</p>'; tpl += '<div style="display: grid;grid-auto-flow: column;column-gap: 20px;align-items: center;justify-content: center;">'; tpl += '<a class="button added_to_cart" onclick="jQuery.unblockUI();" style="font-weight: 400;padding: 10px 15px;letter-spacing: 0;font-size:14px;background-color: transparent;border: 1px solid #e6e6e6;color: #666;">Продолжить</a>'; tpl += '<a href="/shop/cart/" class="button alt added_to_cart" style="font-weight: 400;padding: 10px 15px;letter-spacing: 0;font-size:14px;">Оформить</a>'; tpl += '</div>'; $.blockUI( { message: tpl, timeout: 5000, css: { zIndex: '100000', width: '100%', border: 0, padding: 30, maxWidth: '400px', top: '50%', left: '50%', borderRadius: '4px', cursor: 'default', transform: 'translate(-50%, -50%)' } } ); } } ); } ); </script> <?php } );Только на странице товара по дефолту это работать не будет, только если там реализовано добавление товара через ajax
Большое спасибо