Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created September 20, 2016 08:55
Show Gist options
  • Save remcotolsma/b895d81ffc21ac7ad55d0b7938b4ac75 to your computer and use it in GitHub Desktop.
Save remcotolsma/b895d81ffc21ac7ad55d0b7938b4ac75 to your computer and use it in GitHub Desktop.
Display WooCommerce prices exlcuding tax for distributors.
<?php
/*
Plugin Name: SunStofey WooCommerce Prices Excluding Tax for Distributors
Plugin URI: https://www.pronamic.eu/
Description: Display WooCommerce prices exlcuding tax for distributors.
Author: Pronamic
Version: 1.0.0
Author URI: https://www.pronamic.eu/
*/
/**
* Override WooCommerce tax display option for distributors.
*
* @see http://stackoverflow.com/questions/29649963/displaying-taxes-in-woocommerce-by-user-role
* @see https://github.com/woothemes/woocommerce/blob/v2.2.3/includes/admin/settings/class-wc-settings-tax.php#L147-L158
* @see https://github.com/woothemes/woocommerce/blob/v2.2.3/includes/admin/settings/class-wc-settings-tax.php#L166-L178
* @see https://github.com/WordPress/WordPress/blob/4.6.1/wp-includes/option.php#L37-L52
*/
function sunstofey_override_woocommerce_tax_display( $value ) {
if ( current_user_can( 'distributor' ) ) {
return 'excl';
}
return $value;
}
add_filter( 'pre_option_woocommerce_tax_display_shop', 'sunstofey_override_woocommerce_tax_display' );
add_filter( 'pre_option_woocommerce_tax_display_cart', 'sunstofey_override_woocommerce_tax_display' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment