Skip to content

Instantly share code, notes, and snippets.

@conschneider
Last active April 11, 2020 21:02
WooCommerce add notices for when backorders are (not) allowed.
//output with add to cart button on product detail page
add_action( 'woocommerce_after_add_to_cart_form', 'custom_notice_for_backorders_allowed' );
function custom_notice_for_backorders_allowed()
{
//instantinate product object
global $product;
//check if backorders are allowed
if ( $product->backorders_allowed() )
{
?>
Backorders allowed: Put some text and <a href="#">links here.</a>
<?php
}
}
//output after product title
add_action( 'woocommerce_single_product_summary', 'custom_notice_for_backorders_not_allowed' );
function custom_notice_for_backorders_not_allowed()
{
global $product;
//check if backorders are not allowed
if ( ! $product->backorders_allowed() )
{
?>
Backorders not allowed: Put some text and <a href="#">links here.</a>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment