I want to make a tooltip for the "Flat Rate" delivery option. I need to put the "Question mark" icon next to "Flat Rate" and when I click on it, a prompt should tooltip with a description of the delivery terms.
I have a code that shows an icon, which pops up a shows when clicked.
<div class="popup" onclick="myFunction()"><i class="pe-7s-help1"></i>
<span class="popuptext" id="myPopup">
<?php if ( is_active_sidebar( 'tooltip_sidebar' ) ) : ?>
<div id="tooltip-sidebar" class="sidebar">
<?php dynamic_sidebar( 'tooltip_sidebar' ); ?>
</div>
<?php endif; ?>
</span>
</div>
I am also registering a new sidebar in which I will write the shipping terms.
add_action( 'widgets_init', 'register_new_sidebar' );
function register_new_sidebar() {
register_sidebar(
array(
'id' => 'tooltip_sidebar',
'name' => 'Tooltip Sidebar',
'description' => '',
'before_widget' => '<div id="%1$s" class="tooltip widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
}
CSS style for a tooltip:
/* Popup container */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
}
/* The actual popup (appears on top) */
.popup .popuptext {
visibility: hidden;
width: 320px;
background: #fff;
color: #222;
text-align: center;
padding: 10px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
-webkit-box-shadow: 0px 5px 15px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: 0px 5px 15px 0px rgba(50, 50, 50, 0.3);
box-shadow: 0px 5px 15px 0px rgba(50, 50, 50, 0.3);
}
/* Popup arrow */
.popup .popuptext::after {
content: "X";
position: absolute;
top: 0;
right: 5%;
border-width: 5px;
border-style: solid;
border-color: #fff 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 ;}
}
Script for a tooltip:
<script>
// When the user clicks on <div>, open the popup
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
</script>
Tell me how this icon can be added to the "Flat Rate" delivery option using hooks in the Functions.php file? I just don't want to add this code to WooCommerce templates. And how can you make this code work in the cart and on the checkout page?
I will be glad for your help!
question from:
https://stackoverflow.com/questions/66053315/add-tooltip-to-flat-rate-shipping-method-in-woocommerce 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…