In alcuni casi, potresti voler impostare una speciale categoria di prodotti "In saldo all'ingrosso" che contenga articoli che offrono uno sconto aggiuntivo basato sul Prezzo all'ingrosso, non sul Prezzo normale.
Invece di dover regolare manualmente prezzi o percentuali, è possibile farlo tramite codice per offrire uno sconto aggiuntivo sul prezzo all'ingrosso per gli articoli che appaiono in questa categoria "In saldo all'ingrosso".
Nota che sto parlando specificamente di applicare lo sconto sul prezzo all'ingrosso, non sul prezzo normale. Per regolare la percentuale di sconto sul prezzo normale, usa la funzionalità sconti percentuali per categoria di prodotto.
Questo è inteso come un tutorial avanzato e dovrebbe essere implementato solo se hai una buona comprensione dei ruoli utente e dei termini delle categorie di prodotto.
Aggiungi il seguente snippet di codice al tuo functions.php e regola lo slug della categoria (ho usato "wholesale-on-sale" qui) e la percentuale di sconto che desideri offrire (qui viene usato 0,5 per il 50% di sconto). Puoi anche aggiungere altre condizioni "else if" per testare altri ruoli o altre categorie.
/**
* 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 );
