2016-07-05 11 views
3

Ich habe einige Vorlagen für meinen WooCommerce-Shop bearbeitet. Ich habe den Standardpreis entfernt, weil ich das Plugin WooCommerce Extra Product Options verwende, um den Preis zu aktivieren und einige spezifische Optionen zu kontrollieren.Prüfen, ob das Produkt in WooCommerce herunterladbar ist

Jetzt möchte ich herunterladbare Produkte zu meinem Shop hinzufügen. Das Plugin unterstützt keine Downloads, da es dafür nicht genügend API gibt, sagt der Autor.

Also, ich möchte den Preis zurück in meiner Vorlage, aber nur für Produkte, wo "Download" eingeschaltet ist. Wie kann ich prüfen, ob ein Produkt über die Themes herunterladbar ist? Ansonsten werden alle herunterladbaren Produkte in die Kategorie "Downloads" gestellt, so dass eine Überprüfung, ob das Produkt in dieser Kategorie ist, auch für mich gut ist.

Können Sie mir helfen?

Antwort

2

Sie is_downloadable verwenden können() Funktion von WP. WC_Product :: is_downloadable() - Prüft, ob ein Produkt herunterladbar ist oder nicht.

$bool = WC_Product::is_downloadable(); 

Es befindet sich in

Dateiname: WooCommerce/includes/Abstracts/abstract-WC-product.php

public function is_downloadable() { 
return $this->downloadable == 'yes' ? true : false; 
} 

Genau dies fordern Produkt-Seitenvorlage .

<?php 
if (! defined('ABSPATH')) exit; // Exit if accessed directly 
global $post, $woocommerce, $product; 
if ($product->is_downloadable('yes')) { 
    // Your Logic. 
}else{ 
    // Your Logic. 
} 
?> 

Weitere Details See the Link. und another link

3

Sie können es über is_downloadable Funktion überprüfen. Fügen Sie es überall in Ihrer Produkt-Seitenvorlage hinzu.

<?php 
if (! defined('ABSPATH')) exit; // Exit if accessed directly 
global $post, $woocommerce, $product; 

if ($product->is_downloadable('yes')) { 
    // Your Logic. 
}else{ 
    // Your Logic. 
} 
?> 
Verwandte Themen