remove button specific product and open modal woocommerce
Thu Oct 12 2023 19:55:02 GMT+0000 (Coordinated Universal Time)
Saved by
@naveedrashid
function remove_add_to_cart_button_from_specific_product()
{
$product_id = 23396;
if (is_singular('product') && get_the_ID() == $product_id) {
remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
}
}
add_action('wp', 'remove_add_to_cart_button_from_specific_product');
function add_custom_button()
{
$product_id = 23396;
if (is_singular('product') && get_the_ID() == $product_id) {
echo '<p>' . __('Prices available upon request') . '</p>';
echo '<div class="header-right-icon-group singleBtnId open-modal">';
echo '<a href="javascript:void(0)">' . __('Contact Now') . '</a>';
echo '</div>';
echo '<style>
.single_variation_wrap{
display:none !important;
}
</style>';
?>
<div id="myModal" class="modal product_modal">
<div class="modal-content">
<span class="close">×</span>
<?php echo do_shortcode('[gravityform id="1" title="false" ajax="true"]'); ?>
</div>
</div>
<?php
}
}
add_action('woocommerce_single_product_summary', 'add_custom_button', 31);
function product_modal()
{
?>
<script>
jQuery(document).ready(function() {
jQuery(".open-modal").click(function() {
jQuery("#myModal").css("display", "block");
});
jQuery(".close").click(function() {
jQuery("#myModal").css("display", "none");
});
});
</script>
<?php
}
add_action('wp_head', 'product_modal');
//Modal Css
.modal {
display: none;
position: fixed;
z-index: 9;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0 0 0 / 87%);
padding-top: 60px;
}
.modal-content {
background-color: #fefefe;
margin: 8% auto;
padding: 20px;
border: 1px solid #888;
width: 50%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.product_modal label {
color: #000;
text-transform: uppercase;
font-size: 13px !important;
letter-spacing: 3px;
}
content_copyCOPY
https://trumuse.com/product/bundles-and-hair-clips/
Comments