Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Hide Add to cart button on specific products

/* REMOVE ADD TO CART BUTTON ON SPECIFIC PRODUCT IDs*/
add_filter( 'woocommerce_variation_is_purchasable', 'filter_is_purchasable', 10, 2 );
add_filter('woocommerce_is_purchasable', 'filter_is_purchasable', 10, 2);
function filter_is_purchasable($is_purchasable, $product ) {
    if( in_array( $product->get_id(), not_purchasable_ids() ) ){
         return false;
    } 
    return is_purchasable;
}
function not_purchasable_ids() {
return array( 6202,56078,11406,11410 );
}
/* REMOVE ADD TO CART BUTTON FOR ADMIN USERS */
add_action('wp_loaded','get_user_role');
function get_user_role(){
$current_user = wp_get_current_user();
  if(count($current_user->roles)!==0){
  if($current_user->roles[0]=='administrator'){
add_filter('woocommerce_is_purchasable', '__return_false');
}
}
}
/* REMOVE ADD TO CART BUTTON FOR NON-LOGGED-IN USERS */
if (!is_user_logged_in()) {
// in product page
add_filter('woocommerce_is_purchasable', '__return_false');
}
//Disable Add to Cart button for certain categories
add_action('wp', 'QL_remove_add_to_cart_from_category' );   
function QL_remove_add_to_cart_from_category(){ 
  if( is_product_category( 'laptops' ) ) { 
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); 
  } 
}
//Remove Add to cart button temporarily and automatically display it after a date
add_filter( 'woocommerce_is_purchasable', 'hide_add_to_cart_button_until_date', 10, 2 );
function hide_add_to_cart_button_until_date( $is_purchasable = true, $product ) {
$current_date = date('Y-m-d');
$release_date = date( 'Y-m-d', strtotime('2020-12-15') );
if( strtotime($current_date) < strtotime($release_date) && $product->get_id() == 624 ) {
$is_purchasable = false;
}
return $is_purchasable;
}
Comment

PREVIOUS NEXT
Code Example
Php :: wocommerce product image 
Php :: laravel collection to json 
Php :: laravel create many 
Php :: wordpress options 
Php :: laravel array in lang 
Php :: add phpmyadmin login linux 
Php :: how get the size of image in laravel 
Php :: laravel custom validation rules 
Php :: laravel uuid not showing in query 
Php :: PHP DateTime Format date time according to a time zone 
Php :: inplode php 
Php :: php globals 
Php :: laravel collection first 
Php :: yii 2 create migration with fields 
Php :: laravel updateorcreate multiple records 
Php :: cron job every 5 minutes wordpress 
Php :: mysql_real_escape_string 
Php :: how to get stripe processing fees api 
Php :: laravel admin panel free package 
Php :: PHP - AJAX and PHP 
Php :: laravel store blob image into database 
Php :: Parse error: syntax error, unexpected token "{" in C:xampphtdocsloginsystem1welcome.php on line 3 
Php :: laravel filter array 
Php :: what is cors in laravel 
Php :: js php number format space 
Php :: laravel looping checking if last record has reached 
Php :: change aspect ratio of image php 
Php :: curl_setopt_array php 
Php :: Skip model mutator 
Php :: laravel get url parameter value in controller 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =