Skip to content

Instantly share code, notes, and snippets.

@fervous
Last active September 28, 2018 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fervous/c6d652ebfc715a0faa318bd6955c3ab2 to your computer and use it in GitHub Desktop.
Save fervous/c6d652ebfc715a0faa318bd6955c3ab2 to your computer and use it in GitHub Desktop.
remove add to cart if vacation mode is active - wc vendors pro
//remove add to cart on product page if vacation mode is active
function IsVacation_product_page(){
$vendor_id = get_the_author_meta('ID');
$vacation_mode = get_user_meta( $vendor_id, '_wcv_vacation_mode', true );
if ($vacation_mode){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
add_action('woocommerce_single_product_summary','IsVacation_product_page');
//remove add to cart from loop if vacation mode is active
function IsVacation(){
$vendor_id = get_the_author_meta('ID');
$vacation_mode = get_user_meta( $vendor_id, '_wcv_vacation_mode', true );
if ($vacation_mode)
{
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}
}
add_action('woocommerce_before_shop_loop_item','IsVacation');
@ptrsmk
Copy link

ptrsmk commented Sep 28, 2018

My suggestion…

add_filter( 'woocommerce_is_purchasable', 'woocommerce_rummel_is_purchasable', 10, 2 );
function woocommerce_rummel_is_purchasable( $is_purchasable, $product ) {

    $vendor_id = $product->post->post_author;
    $vacation_mode = get_user_meta( $vendor_id, '_wcv_vacation_mode', true );

    if( $vacation_mode ) $is_purchasable = false;

    return $is_purchasable;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment