Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created July 3, 2020 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/29b84c37acb2734e1d90b1dbdce239c9 to your computer and use it in GitHub Desktop.
Save finalwebsites/29b84c37acb2734e1d90b1dbdce239c9 to your computer and use it in GitHub Desktop.
Different stock status names for your WooCommerce product detail page
<?php
/*
Using this function you can use different values on the frontend while keeping the original strings or translations.
How to use:
Place the PHP code below into the functions.php file from your WordPress child theme.
If you like, change the strings inside the quotes for the $status variables.
The action hook will place the information below the add to cart button (based on the original WooCommerce template files).
*/
function add_stock_status_info() {
global $product;
$stock_status = $product->get_stock_status();
switch ($stock_status) {
case 'instock':
$status = 'Uit voorraad leverbaar';
break;
case 'onbackorder':
$status = 'Levertijd 3-5 werkdagen';
break;
case 'outofstock':
$status = 'Niet meer leverbaar';
break;
default:
$status = '';
break;
}
if ($status) echo '
<div class="voorraad">'.$status.'</div>';
}
add_action('woocommerce_single_product_summary', 'add_stock_status_info', 30);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment