0

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>';

      }

  }
}

}
2
  • What do you mean by jQuery doesn't work? Are you getting any errors? Anyways if it is purely related to jQuery, you better ask at StackOverflow as pure HTML/CSS/jQuery specific questions are off-topic here
    – bravokeyl
    Commented Jul 19, 2016 at 13:48
  • No errors but my script has no effect even if its properly called in the DOM.
    – Zac
    Commented Jul 19, 2016 at 14:12

1 Answer 1

0

this not perfect way to write inline java script , write java script into document ready event

jQuerydocument ).ready(function() {
    jQuery( ".wc-proceed-to-checkout" ).css("display", "none");
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.