Last active
March 26, 2019 21:29
-
-
Save tradesouthwest/f273cd0ec5eafef73c44578a09e08f1b to your computer and use it in GitHub Desktop.
Woocommerce remove quick view button if vendor on vacation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Footer script to remove quick view button if vendor on vacation. | |
* @param script | |
* @author Larry Judd | Tradesouthwest | |
* The first one works the best across all browsers. The other two are for testing against other plugins. | |
*/ | |
/* | |
* If you use the .css combinator method add this to CSS stylesheet: | |
****************************************************************** | |
.wcmp-vacant{ | |
display:none; | |
} | |
.wcmp_add_to_cart_message:before{ | |
content: "_"; | |
position: relative; | |
display: block; | |
height:3em; | |
min-width: 150px; | |
color:transparent; | |
background: rgba(252,252,252,.68); | |
top: -2.67em; | |
margin-bottom: -3em; | |
z-index: 100; | |
} | |
******************************************************************** | |
*/ | |
add_action( 'wp_footer', 'remove_qvbutton_whenvendon_vacation', 10 ); | |
function remove_qvbutton_whenvendon_vacation() | |
{ | |
global $product; | |
ob_start(); | |
$html = ''; | |
$vendor_product = get_wcmp_product_vendors($product->id); | |
$vendor_vacation_set_up = get_user_meta($vendor_product->id, '_vacation_include_dates', true); | |
if( $vendor_vacation_set_up['shop_closed_text'] ) | |
{ | |
echo '<script>jQuery(document).ready(function(){ | |
if ( jQuery("a.wc-quick-view-button + p.wcmp_add_to_cart_message").length | |
|| jQuery("a.wc-quick-view-button.button.alt + .wcmp_add_to_cart_message").length | |
) { | |
jQuery("a.wc-quick-view-button").addClass("wcmp-vacant"); | |
} else { | |
jQuery("a.wc-quick-view-button").removeClass("wcmp-vacant"); | |
} | |
} ); </script>'; | |
} | |
$html = ob_get_clean(); | |
print $html; | |
} | |
//alt method, works on most themes. | |
add_action( 'wp_footer', 'remove_qvbutton_whenon_vacation', 40 ); | |
function remove_qvbutton_whenon_vacation() | |
{ | |
global $product; | |
$html = ''; | |
$vendor_product = get_wcmp_product_vendors($product->id); | |
if ($vendor_product) | |
{ | |
ob_start(); | |
echo '<script>jQuery(document).ready(function($){ | |
if (jQuery(".add_to_cart_button").length ) { | |
jQuery("a.wc-quick-view-button").css({"visibility":"visible"}); | |
} else { | |
jQuery("a.wc-quick-view-button").css({"visibility":"hidden"}); | |
} | |
} ); </script>'; | |
$html = ob_get_clean(); | |
print $html; | |
} | |
return false; | |
} | |
/** | |
* Footer script to remove quick view button if vendor on vacation. | |
* @param script | |
* @author Larry Judd | Codeable | |
*/ | |
add_action( 'wp_footer', 'remove_qview_whenon_vacation', 33 ); | |
function remove_qview_whenon_vacation() | |
{ | |
global $product; | |
$vendor_product = get_wcmp_product_vendors($product->id); | |
if ($vendor_product) { | |
$vendor_vacation_set_up = get_user_meta($vendor_product->id, '_vacation_include_dates', true); | |
if(isset($vendor_vacation_set_up['avoid_purchase'])) : | |
?><script>jQuery(document).ready(function($){if (jQuery(".wcmp_add_to_cart_message").length){ jQuery(".wc-quick-view-button").hide();} else {jQuery(".wc-quick-view-button").show();} } ); </script> | |
<?php endif; | |
} | |
} | |
/** | |
* Footer script to remove quick view button if vendor on vacation. | |
* @param script-secondary option | |
* @author Larry Judd | Codeable | |
* @maybe_use .wcmp_vacation_avoid_add_to_cart_msg | |
*/ | |
add_action( 'wp_footer', 'remove_qview_whenon_vacation', 40 ); | |
function remove_qview_whenon_vacation() | |
{ | |
global $product; | |
$html =null; | |
$vendor_product = get_wcmp_product_vendors($product->id); | |
if ($vendor_product) { | |
$vendor_vacation_set_up = get_user_meta($vendor_product->id, '_vacation_include_dates', true); | |
if(isset($vendor_vacation_set_up['avoid_purchase'])) : | |
ob_start(); | |
$html =''; | |
echo '<script>jQuery(document).ready(function($){if (jQuery(".wcmp_add_to_cart_message").length){ jQuery(".wc-quick-view-button").hide();} else {jQuery(".wc-quick-view-button").show();} } ); </script>'; | |
$html = ob_get_clean(); | |
endif; | |
} | |
echo $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment