I have the following snippet to prevent the purchase of products by displaying a text and hiding the "proceed to checkout" button. The text part works great but the jQuery part doesn't i don't know why. Any ideas ? Thanks.
function wc_minimum_order_amount_premium() {
$minimum = 8;
if ( WC()->cart->cart_contents_count < $minimum ) {
$draught_links = array();
foreach(WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$terms = get_the_terms( $_product->id, 'product_cat' );
foreach ($terms as $term) {
$draught_links[] = $term->name;
}
}
if (in_array("PREMIUM", $draught_links)){
$on_draught = true;
}else{
$on_draught = false;
}
if( is_cart() ) {
if($on_draught){
wc_print_notice(
sprintf( 'Vous devez avoir un minimum de %s pour finaliser cette commande, vous en avez %s au total.' ,
$minimum ,
WC()->cart->cart_contents_count
), 'error'
);
echo '<script type="text/javascript"> jQuery( ".wc-proceed-to-checkout" ).css("display", "none");</script>';
}
} else {
if($on_draught){
wc_add_notice(
sprintf( 'Vous devez avoir un minimum de %s pour finaliser cette commande, vous en avez %s au total.' ,
$minimum ,
WC()->cart->cart_contents_count
), 'error'
);
echo '<script type="text/javascript"> jQuery( ".wc-proceed-to-checkout" ).css("display", "none");</script>';
}
}
}
}