Forums › Popup Notices for WooCommerce › Is there a possible solution to trigger a notification modal via Javascript?
- Support forum for the WooCommerce Popups: Cart, Add to Cart, Checkout Notices to Popups.
- This topic has 4 replies, 4 voices, and was last updated 1 year, 4 months ago by
Malwin Boehringer.
-
AuthorPosts
-
May 21, 2021 at 4:50 pm #99905
Malwin Böhringer
GuestHi there, thank you so much for this Plugin. It’s what I was looking for, but as i’m develeping some additional WC functionalities (REST API)… is there a possible solution to trigger a custom notification modal via Javascript? That would be awesome. All the Best! Malwin
May 23, 2021 at 3:11 pm #99906Pablo Pacheco
ParticipantThanks for the kind words 🙂
I believe you could try something like this:
document.addEventListener('DOMContentLoaded', function () { ttt_pnwc.clearPopupMessages(); ttt_pnwc.messages.push({message: 'Message 1', type: 'success'}); ttt_pnwc.messages.push({message: 'Message 2', type: 'error'}); ttt_pnwc.messages.push({message: 'Message 3', type: 'info'}); ttt_pnwc.addMessagesToPopup(); ttt_pnwc.openPopup(); });September 11, 2024 at 2:27 pm #149946Malwin Boehringer
ParticipantHi Pablo,
I get some trouble with the implementation after updating from V. 1.3.5 to V 1.5.
Did the name of the class function “ttt_pnwc…” change somehow?
Old solution gets a console error by trying to push a message: “Uncaught ReferenceError: ttt_pnwc is not defined”
Thank you in Advanced. MalwinSeptember 12, 2024 at 2:21 pm #150043pablo-pacheco
ParticipantHi,
It kind of did.
Please, try it like this. It should do the trick
jQuery( 'body' ).on( 'ttt_pnwc', function ( ttt_pnwcObj ) { ttt_pnwc = ttt_pnwcObj.obj; ttt_pnwc.clearPopupMessages(); ttt_pnwc.messages.push( { message: 'Message 1', type: 'success' } ); ttt_pnwc.messages.push( { message: 'Message 2', type: 'error' } ); ttt_pnwc.messages.push( { message: 'Message 3', type: 'info' } ); ttt_pnwc.addMessagesToPopup(); ttt_pnwc.openPopup(); } );September 30, 2024 at 2:19 pm #150903Malwin Boehringer
ParticipantHi Pablo, Thank you for the suggestion but I could not get it to work as expected.
So I simply copied the frontend functions direct from the pluginfolder,
now it works fine with the use of some woocommerce native php function if the page reloads “wc_add_notice( __(‘hello world’, ‘mytheme’ ), ‘info’ );”:
—function showStatusMessage (text, msgtype) { if (typeof text !== 'string' || typeof msgtype !== 'string') { console.error('Invalid input: text and msgtype must be strings') return } jQuery('#ttt-pnwc-notice').find('.ttt-pnwc-content').empty() const value = { type: msgtype, message: text } jQuery('#ttt-pnwc-notice .ttt-pnwc-content').append(` <div class='ttt-pnwc-notice ${value.type} ttt-static'> <i class='ttt-pnwc-notice-icon default-icon'></i> <div class='ttt-pnwc-message'>${value.message}</div> </div> `) MicroModal.show('ttt-pnwc-notice') setTimeout(() => { MicroModal.close() }, 4000) } -
AuthorPosts
- You must be logged in to reply to this topic.