• Resolved Anonymous User 16103310

    (@anonymized-16103310)


    I have installed this plugin to be able to add click-open popups in my WooCommerce storefront website, but popups don’t seem to be working. Below is my snippet

    add_filter( 'woocommerce_product_tabs', 'woo_shipping_returns_product_tab' );
    
    function woo_shipping_returns_product_tab( $tabs ) {
      
      $tabs['ship_tab'] = array(
    	'title' 	=> __( 'Shipping & Returns', 'woocommerce' ),
    	'priority' 	=> 50,
    	'callback' 	=> 'woo_shipping_returns_product_tab_content'
      );
      
      return $tabs;
    
    }
    
    function woo_shipping_returns_product_tab_content() {
      echo '<p class="popup" onclick="myFunction()">Pay on delivery<span class="popuptext" id="myPopup">Cash, Card, and Mobile Money</span></p>';
    	
    }
    
    add_action( 'wp_head', function () { ?>
    <script>
    
    		function myFunction() {
    		  var popup = document.getElementById("myPopup");
    		  popup.classList.toggle("show");
    		}
    
    </script>
    <?php } );

    And my CSS in WordPress customizer looks like this

    /* The actual popup (appears on top) */
    .popup .popuptext {
      visibility: hidden;
      width: 160px;
      background-color: #555;
      color: #fff;
      text-align: center;
      border-radius: 6px;
      padding: 8px 0;
      position: absolute;
      z-index: 1;
      bottom: 125%;
      left: 50%;
      margin-left: -80px;
    }
    
    /* Popup arrow */
    .popup .popuptext::after {
      content: "";
      position: absolute;
      top: 100%;
      left: 50%;
      margin-left: -5px;
      border-width: 5px;
      border-style: solid;
      border-color: #555 transparent transparent transparent;
    }
    
    /* Toggle this class when clicking on the popup container (hide and show the popup) */
    .popup .show {
      visibility: visible;
      -webkit-animation: fadeIn 1s;
      animation: fadeIn 1s
    }
    
    /* Add animation (fade in the popup) */
    @-webkit-keyframes fadeIn {
      from {opacity: 0;}
      to {opacity: 1;}
    }
    
    @keyframes fadeIn {
      from {opacity: 0;}
      to {opacity:1 ;}
    }
Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @abanista,

    Looks like there were a few issues with how your JavaScript was written:

    
    add_filter( 'woocommerce_product_tabs', function ( $tabs ) {
    
    	$tabs['ship_tab'] = array(
    		'title'    => __( 'Shipping & Returns', 'woocommerce' ),
    		'priority' => 50,
    		'callback' => function () {
    			echo '<p class="popup" id="myPopup">Pay on delivery<span class="popuptext">Cash, Card, and Mobile Money</span></p>';
    		},
    	);
    
    	return $tabs;
    } );
    
    
    add_action( 'wp_head', function () { ?>
    	<script>
    		const popup = document.getElementById('myPopup')
    
    		if (popup) {
    			popup.addEventListener('click', function () {
    				const popupText = popup.querySelector('.popuptext')
    				popupText.classList.toggle('show')
    			})
    		}
    	</script>
    <?php } );
    
Viewing 1 replies (of 1 total)

The topic ‘Snippet not working’ is closed to new replies.