Is there a possible solution to trigger a notification modal via Javascript?

Forums Popup Notices for WooCommerce Is there a possible solution to trigger a notification modal via Javascript?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #99905
    Malwin Böhringer
    Guest

    Hi 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

    #99906
    Pablo Pacheco
    Participant

    Thanks 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();
    });
    
    #149946
    Malwin Boehringer
    Participant

    Hi 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. Malwin

    #150043
    pablo-pacheco
    Participant

    Hi,

    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();
    } );
    #150903
    Malwin Boehringer
    Participant

    Hi 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)
    }
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.