Skip to content

Instantly share code, notes, and snippets.

@hslaszlo
Created October 5, 2023 09:41
Show Gist options
  • Save hslaszlo/04a4ab736728ba683ac25643a408d0ed to your computer and use it in GitHub Desktop.
Save hslaszlo/04a4ab736728ba683ac25643a408d0ed to your computer and use it in GitHub Desktop.
overide the settings for allowing to purchase out of stock products
<?php
// The following hooked functions will allow you to make everything purchasable:
// Change all products stock statuses to 'instock'
add_filter( 'woocommerce_product_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
function filter_get_stock_status_callback( $stock_status, $product ){
return is_admin() ? $stock_status : 'instock';
}
// Enable backorders on all products
add_filter( 'woocommerce_product_get_backorders', 'filter_get_backorders_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_backorders', 'filter_get_backorders_callback', 10, 2 );
function filter_get_backorders_callback( $backorders_status, $product ){
return 'yes'; // Enable without notifications
}
// Remove the stock quantity from displayed stock status
add_filter( 'woocommerce_get_availability_text', 'filter_get_availability_text_callback', 10, 2 );
function filter_get_availability_text_callback( $availability_text, $product ){
return __( 'In stock', 'woocommerce');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment