Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Plugin Name: Back In Stock Notifications
* Plugin URI: https://woocommerce.com/products/back-in-stock-notifications/
* Description: Use this snippet to hide the "Notify Me" form for specific products
* Version: 1.0
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 3.8
* Tested up to: 5.3
*2021
* Copyright: © 2021 Automattic
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_action( 'init', 'sw_bis_init_blocked_products' );
function sw_bis_init_blocked_products() {
add_filter( 'woocommerce_bis_validate_product_sync', 'sw_bis_validate_product_sync', 10, 2 );
add_filter( 'woocommerce_bis_is_available_for_product', 'sw_bis_is_available_for_product', 10, 2 );
}
// This filter will prevent products to be synced for broadcasting.
function sw_bis_validate_product_sync( $valid, $product ) {
$product_ids_to_be_blocked = array( 31, 32 ); // Replace with product IDS.
if ( in_array( $product->get_id(), $product_ids_to_be_blocked ) ) {
return false;
}
return $valid;
}
// This filter will prevent BIS form for displaying in the FrontEnd.
function sw_bis_is_available_for_product( $is_available, $product ) {
$product_ids_to_be_blocked = array( 31, 32 ); // Replace with product IDS.
if ( in_array( $product->get_id(), $product_ids_to_be_blocked ) ) {
return false;
}
return $is_available;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment