1. Startseite
  2. Wissensdatenbank
  3. WooCommerce Wholesale Prices Premium
  4. Großhandelspreise
  5. So geben Sie einen weiteren Rabatt auf den Großhandelspreis, wenn sich ein Produkt in einer bestimmten Kategorie befindet

So geben Sie einen weiteren Rabatt auf den Großhandelspreis, wenn sich ein Produkt in einer bestimmten Kategorie befindet

In einigen Fällen möchten Sie vielleicht eine spezielle Produktkategorie „Großhandel im Angebot“ einrichten, die Artikel enthält, die einen zusätzlichen Rabatt basierend auf dem Großhandelspreis und nicht auf dem regulären Preis gewähren.

Anstatt Preise oder Prozentsätze manuell anpassen zu müssen, ist es möglich, dies im Code zu tun, um Artikel, die in dieser „Großhandel im Angebot“-Kategorie erscheinen, einen zusätzlichen Rabatt auf den Großhandelspreis zu gewähren.

Beachten Sie, dass ich speziell davon spreche, den Rabatt vom Großhandelspreis und nicht vom regulären Preis abzuziehen. Für die Anpassung des %-Rabatts auf den regulären Preis verwenden Sie dafür die Funktion Produktkategorierabatte in Prozent.

Dies ist als fortgeschrittenes Tutorial gedacht und sollte nur implementiert werden, wenn Sie ein gutes Verständnis von Benutzerrollen und Produktkategoriebegriffen haben.

Fügen Sie den folgenden Code-Schnipsel zu Ihrer functions.php hinzu und passen Sie den Kategorie-Slug (ich habe hier „wholesale-on-sale“ verwendet) und den gewünschten Rabattprozentsatz an (hier wird 0,5 für 50 % Rabatt verwendet). Sie können auch weitere „else if“-Bedingungen hinzufügen, um andere Rollen oder andere Kategorien zu testen.

/**
* Add further discount on top of a product's wholesale price.
* The function below give a further discount on the wholesale price for items in the "Wholesale On Sale" category.
* Important Note: Please adjust this functions code accordingly to fit your needs.
*/
function wwppAddDiscountToSaleCategory( $wholesalePrice , $product_id , $userWholesaleRole ) {

// Get all the category slugs this product belongs to
$terms      = wp_get_post_terms( $product_id, 'product_cat' );
$categories = array();

foreach ( $terms as $term )
$categories[] = $term->slug;

/**
* Check if this product is under the "wholesale-on-sale" product category.
* Assuming that we wanted to apply 50% off on all products under this category on top of their existing wholesale price
* Please change 'wholesale-on-sale' category accordingly to fit your needs.
*/
if ( in_array( 'wholesale-on-sale', $categories ) ) {

/**
* Check if the current user have a role of 'wholesale_customer'.
* Assuming we wanted to have this effect on all users under 'wholesale_customer' role.
* Please change the role accordingly to fit your needs.
*/
if ( in_array( 'wholesale_customer', $userWholesaleRole ) ) {

/**
* In this example we are using 50% discount off from the product existing "wholesale price".
* Please change accordingly to fit your needs.
*/
if ( is_array( $wholesalePrice ) && isset( $wholesalePrice[ 'wholesale_price' ] ) )
$wholesalePrice[ 'wholesale_price' ] = $wholesalePrice[ 'wholesale_price' ] - ( $wholesalePrice[ 'wholesale_price' ] * 0.5 );
else
$wholesalePrice = $wholesalePrice - ( $wholesalePrice * 0.5 );

}

// You can add more else if conditions here if you want to test for other wholesale roles

}

// you can add more else if conditions here to test for other product categories

return $wholesalePrice;
}

add_filter( 'wwp_filter_wholesale_price_shop_v2', 'wwppAddDiscountToSaleCategory', 100, 3 );

add_filter( 'wwp_filter_wholesale_price_cart', 'wwppAddDiscountToSaleCategory', 100, 3 );

// You only need to uncomment this if you are using WooCommerce Wholesale Prices plugin lower than verison 1.6.x
// If you are on the latest version of our plugins, no need to uncomment this code to improve performance
// add_filter( 'wwp_filter_wholesale_price', 'wwppAddDiscountToSaleCategory', 100, 3 );
War dieser Artikel hilfreich?

Verwandte Artikel

Benötigen Sie Unterstützung?

Können Sie die Antwort, die Sie suchen, nicht finden?
Support kontaktieren
Kauf abschließen