Dans WooCommerce J'ai un code personnalisé pour masquer la TVA pour des rôles utilisateur spécifiques, et il fonctionne parfaitement pour tous les rôles sauf pour un appelé Platinum, où il ne cache pas la TVA mais reste comme tous les rôles utilisateur par défaut.Masquer la TVA pour des rôles utilisateur spécifiques dans WooCommerce
Ce que j'ai besoin est pour ce code pour cacher la TVA pour le platine aussi - il le fait pour les autres rôles que j'énuméré
Comment puis-je le faire fonctionner pour mon rôle d'utilisateur « platine » aussi?
C'est le code que j'utilise:
/**
* Function that will check for user role and turn off VAT/tax for that role
*/
function wc_diff_rate_for_user() {
// check for the user role
if (is_user_logged_in() && current_user_can('bronze', 'sølv', 'guld', 'platinum')) {
// set the customer object to have no VAT
WC()->customer->is_vat_exempt = true;
}
}
add_action('template_redirect', 'wc_diff_rate_for_user', 1);
/**
* Function that filters the variable product hash based on user
*/
function wc_get_variation_prices_hash_filter($hash, $item, $display) {
// check for the user role
if (is_user_logged_in() && current_user_can('bronze', 'sølv', 'guld', 'platinum')) {
// clear key 2, which is where taxes are
$hash['2'] = array();
}
// return the hash
return $hash;
}
add_filter('woocommerce_get_variation_prices_hash', 'wc_get_variation_prices_hash_filter', 1, 3);
/**
* Function that removes the price suffix (inc. Tax) from variable products based on role
*/
function wc_get_price_suffix_filter($price_display_suffix, $item) {
// check for the user role
if (is_user_logged_in() && current_user_can('bronze', 'sølv', 'guld', 'platinum')) {
// return blank if it matches
return '';
}
// return if unmatched
return $price_display_suffix;
}
add_filter('woocommerce_get_price_suffix', 'wc_get_price_suffix_filter', 10, 2);
//B2B Roller
add_role('bronze', __(
'Bronze'),
array(
'read' => false, // Allows a user to read
'create_posts' => false, // Allows user to create new posts
'edit_posts' => false, // Allows user to edit their own posts
)
);
add_role('sølv', __(
'Sølv'),
array(
'read' => false, // Allows a user to read
'create_posts' => false, // Allows user to create new posts
'edit_posts' => false, // Allows user to edit their own posts
)
);
add_role('guld', __(
'Guld'),
array(
'read' => false, // Allows a user to read
'create_posts' => false, // Allows user to create new posts
'edit_posts' => false, // Allows user to edit their own posts
)
);
add_role('platinum', __(
'Platinum'),
array(
'read' => false, // Allows a user to read
'create_posts' => false, // Allows user to create new posts
'edit_posts' => false, // Allows user to edit their own posts
)
);
Il vient avec une erreur une fois que je l'ai remplacé avec mon code actuel. J'ai joint l'erreur en haut du message, car il était trop long pour poster ici. – eMikkelsen
@eMikkelsen J'ai mis à jour la fonction conditionnelle (à la fin). Essayez-le s'il vous plaît. Merci – LoicTheAztec
Cela a fonctionné !! Fantastique! – eMikkelsen