Wg: Ersparnis in % als Artikeloverlay

  • Hallo zusammen,

    ich möchte für meinen Shop, der Lebensmittel kurz vor oder über dem MHD verkauft, ein Artikeloverlay Button erstellen, der die Ersparnis in % angibt.

    "Spare x%"

    Natürlich ist ein Artikeloverlay schon vorhanden mit der Aufschrift "ANGEBOT!" (onsale)

    So jetzt hat der Kollege google mir bei der Suche einen Code aus dem Forum ausgeschmissen http://forum.wpde.org/onlineshop-mit…u-anzeigen.html

    Code
    [COLOR=#0000BB][FONT=monospace]add_filter[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'woocommerce_sale_price_html'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'woocommerce_custom_sales_price'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]10[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]2 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
     
     function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]woocommerce_custom_sales_price[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$price[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$product [/FONT][/COLOR][COLOR=#007700][FONT=monospace]) { 
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$percentage [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]round[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( ( ( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$product[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]regular_price [/FONT][/COLOR][COLOR=#007700][FONT=monospace]- [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$product[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sale_price [/FONT][/COLOR][COLOR=#007700][FONT=monospace]) / [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$product[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]regular_price [/FONT][/COLOR][COLOR=#007700][FONT=monospace]) * [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]100 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]); 
     return [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'<div class="saleprice">' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$price [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sprintf[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]' Spare %s'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'woocommerce' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$percentage [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'%</div>' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
    }  [/FONT][/COLOR]

    Ich habe folgende Zeile mehrmals verändert. Die letzten kläglichen Versuche sahen dann so aus:

    Code
    [COLOR=#007700][FONT=monospace]return [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'<span class="saleprice">' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$price [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]sprintf[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]' Spare %s'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'woocommerce' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$percentage [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'%</span>' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]);[/FONT][/COLOR]


    oder

    Code
    return '<span class="onsale">'.__(' Spare %s', 'woocommerce' ), $percentage . '%</span>' );


    Meine Änderungen (die Experten werden erkennen, dass ich keinen Schimmer davon habe) führen aber entweder dazu, dass der Artikelpreis dann auch nicht mehr angezeigt wird oder direkt der Kollege Whitescreen kommt und mich auslacht.

    Danke euch vorab.

    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!