woocommerce_stock_html

FILTER woocommerce\includes\wc-template-functions.php (ligne 3952) github
Get HTML to show product stock.
traduction française
Obtenir du HTML pour afficher le stock de produits.

Paramètres

Entrée :
$html, $availability['availability'], $product
Sortie :
@param  WC_Product $product Product Object.
@return string

Utilisation

Personnaliser l'affichage du stock

Modifier le message de disponibilité

ui
// HTML stock personnalisé
add_filter('woocommerce_get_stock_html', 'html_stock_personnalise', 10, 2);

function html_stock_personnalise($html, $product) {
    $stock_quantity = $product->get_stock_quantity();
    
    if ($product->is_in_stock()) {
        if ($stock_quantity > 10) {
            $html = '

✓ En stock (nombreuses unités)

'; } elseif ($stock_quantity > 0) { $html = '

⚠️ Stock limité (' . $stock_quantity . ' restants)

'; } else { $html = '

✓ Disponible

'; } } else { $html = '

✗ Rupture de stock - Retour prévu sous 10 jours

'; } return $html; }

Actualités

Chargement des actualités...