button display on condition woocommerce code example

Example 1: button display on condition woocommerce

<script>
jQuery(document).ready(function($){

   if ( $( '#step-1' ).hasClass( 'active' ) ) {
         $( '.button-prev' ).hide();
   }

   $("#action-next").click(function(){

         $( '.button-prev' ).show();

         if ( $( '#step-3' ).hasClass( 'active' ) ) {
               $( '.button-next' ).hide();
         } else {
               $( '.button-next' ).show();
         }
   });

   $("#action-prev").click(function(){

       $( '.button-next' ).show();

       if ( $( '#step-1' ).hasClass( 'active' ) ) {
              $( '.button-prev' ).hide();
       }
   });

});
</script>

Example 2: button display on condition woocommerce

add_action('wp_head','thwmscf_hide_next_button');
function thwmscf_hide_next_button(){
 if(is_checkout()){
   $have_category = false;

   foreach ( WC()->cart->get_cart() as $item_key => $item_value ){
     $_product = $item_value['data'];
     $product_id = $_product->get_id();

     if(has_term( 'category_name', 'product_cat', $product_id)){
       $have_category = true;
     }  
   }

   if(!$have_category){
     ?>
     <style type="text/css">
       .thwmscf-buttons .button-next{
         display: none !important;
       }
     </style>
     <?php
   }
 }
}

Tags:

Php Example