Möchtest du andere Vorlagen anzeigen, wenn diese keinen Preis haben? Dann ist dieser Hook sehr gut dafür geeignet.
Hierbei handelt es sich nur um zwei Beispiele. Alle Details zum Hook findest du auf dieser Seite.
Andere Vorlage ausgeben, wenn Preis gleich 0
Mit diesem Hook übersteuerst du zum Beispiel die Vorlage 4567 mit der Vorlage 1234, wenn der Verkaufspreis des Produktes gleich 0 ist:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function modify_template_product( $template, $productid, $content ) { if($template == '4567') { require_once ATKP_PLUGIN_DIR.'/includes/atkp_product.php'; $product = atkp_product::load($productid); if($product->salepricefloat == 0) { return '1234'; } } return $template ; } add_filter( 'atkp_modify_template_product', 'modify_template_product', 10, 3); |
Andere Vorlage, wenn keine Angebote vorhanden sind
Möchtest du eine andere Vorlage anzeigen, wenn es überhaupt keine Angebote mehr gibt (die einen Verkaufspreis haben), kannst du diesen Hook verwenden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
function modify_template_product( $template, $productid, $content ) { if($template == '4567') { require_once ATKP_PLUGIN_DIR.'/includes/atkp_product.php'; $myproduct = atkp_product::load($productid); //Offers section if(!is_array($myproduct->offers)) $offers = array(); else $offers = $myproduct->offers; $offer = new atkp_product_offer(); $offer->shopid= $myproduct->shopid; $offer->link = $myproduct->producturl; $offer->price = $myproduct->saleprice; $offer->pricefloat = $myproduct->salepricefloat; array_push($offers, $offer); $offercount = 0; foreach($offers as $offer) { if($offer->pricefloat == (float)0 || $offer->hideoffer) continue; $offercount++; } if($offercount == 0) return '1234'; } return $template ; } add_filter( 'atkp_modify_template_product', 'modify_template_product', 10, 3); |
Tipp: Verwende ein Plugin wie My Custom Functions oder ein Child-Theme, um deine Hooks einzubauen!