admin管理员组文章数量:1279124
I'm trying to create custom popup box for all loop products in woocommerce shop page. But it's not working, i think it need some code correction,
functions.php code
add_action( 'woocommerce_after_shop_loop_item', 'product_visibility_button', 5 );
function product_visibility_button() {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) ) {
?>
<button type="button" class="button" id="but" style="margin:10px" >Open Popup</button>
<div style="display: none;" class="pop-outer">
<div class="pop-inner">
<button class="close">X</button>
<h2>This is a custom pop-up example</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<?php
}
}
}
jquery code
$(document).ready(function (){
$(".open").click(function (){
$(".pop-outer").fadeIn("slow");
});
$(".close").click(function (){
$(".pop-outer").fadeOut("slow");
});
});
CSS
.pop-outer {
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.pop-inner {
background-color: #fff;
width: 500px;
height: 300px;
padding: 25px;
margin: 5% auto;
}
See also attached screenshot
Is it possible to display for all products ?
I'm trying to create custom popup box for all loop products in woocommerce shop page. But it's not working, i think it need some code correction,
functions.php code
add_action( 'woocommerce_after_shop_loop_item', 'product_visibility_button', 5 );
function product_visibility_button() {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) ) {
?>
<button type="button" class="button" id="but" style="margin:10px" >Open Popup</button>
<div style="display: none;" class="pop-outer">
<div class="pop-inner">
<button class="close">X</button>
<h2>This is a custom pop-up example</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<?php
}
}
}
jquery code
$(document).ready(function (){
$(".open").click(function (){
$(".pop-outer").fadeIn("slow");
});
$(".close").click(function (){
$(".pop-outer").fadeOut("slow");
});
});
CSS
.pop-outer {
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.pop-inner {
background-color: #fff;
width: 500px;
height: 300px;
padding: 25px;
margin: 5% auto;
}
See also attached screenshot
Is it possible to display for all products ?
Share Improve this question asked Nov 16, 2021 at 10:59 Dhruv SutharDhruv Suthar 254 bronze badges 3 |1 Answer
Reset to default 1Use below code. Tested and Worked perfectly.
functions.php
add_action( 'woocommerce_after_shop_loop_item', 'product_visibility_button', 5 );
function product_visibility_button() {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) ) {
?>
<button type="button" class="button" id="but" style="margin:10px" >Open Popup</button>
<div style="display: none;" class="pop-outer">
<div class="pop-inner">
<button class="close">X</button>
<h2>This is a custom pop-up example</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<?php
}
}
}
jQuery Code
jQuery(document).ready(function (){
jQuery(".button").click(function (){
jQuery(this).next().fadeIn("slow");
});
jQuery(".close").click(function (){
jQuery(this).closest(".pop-outer").fadeOut("slow");
});
});
CSS Code
.pop-outer {
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
}
.pop-inner {
background-color: #fff;
width: 500px;
height: auto;
padding: 25px;
margin: 5% auto;
}
本文标签: How to create custom popup in shop page on every loop products
版权声明:本文标题:How to create custom popup in shop page on every loop products? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741217367a2360305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
woocommerce_before_shop_loop_item
,woocommerce_before_shop_loop_item_title
,woocommerce_shop_loop_item_title
,woocommerce_after_shop_loop_item_title
,woocommerce_after_shop_loop_item
. You can see them here. – Buttered_Toast Commented Nov 16, 2021 at 11:09.closest()
and then.find()
the popup element – Buttered_Toast Commented Nov 16, 2021 at 11:12