Created
July 3, 2020 19:24
-
-
Save finalwebsites/29b84c37acb2734e1d90b1dbdce239c9 to your computer and use it in GitHub Desktop.
Different stock status names for your WooCommerce product detail page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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