Skip to content

Instantly share code, notes, and snippets.

@conschneider
Last active April 11, 2020 21:02
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 conschneider/ecc3909070dcf04ea925429b5e8b76b3 to your computer and use it in GitHub Desktop.
Save conschneider/ecc3909070dcf04ea925429b5e8b76b3 to your computer and use it in GitHub Desktop.
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