WC_Settings_Tax::tax_configuration_validation_noticepublicWC 10.5.0

Display admin notice when tax-inclusive pricing is enabled without a base tax rate.

Method of the class: WC_Settings_Tax{}

Returns

null. Nothing (null).

Usage

$WC_Settings_Tax = new WC_Settings_Tax();
$WC_Settings_Tax->tax_configuration_validation_notice(): void;

Changelog

Since 10.5.0 Introduced.

WC_Settings_Tax::tax_configuration_validation_notice() code WC 10.5.0

<?php
public function tax_configuration_validation_notice(): void {
	// Only show on WooCommerce settings pages.
	$screen = get_current_screen();
	if ( ! $screen || 'woocommerce_page_wc-settings' !== $screen->id ) {
		return;
	}

	// Don't show if taxes are disabled.
	if ( ! wc_tax_enabled() ) {
		return;
	}

	// Check if prices are entered with tax.
	if ( 'yes' !== get_option( 'woocommerce_prices_include_tax' ) ) {
		return;
	}

	/**
	 * Filters if taxes should be removed from locations outside the store base location.
	 *
	 * The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing
	 * with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10
	 * regardless of location and taxes.
	 *
	 * @since 2.4.7
	 *
	 * @param bool $adjust_non_base_location_prices True by default.
	 */
	if ( ! apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ) {
		return;
	}

	// Check if base location has tax rates configured.
	$base_location = wc_get_base_location();
	if ( empty( $base_location['country'] ) ) {
		return;
	}

	$has_base_rate = $this->has_standard_tax_rate_for_country( $base_location['country'] );

	// If no base rates exist, show warning.
	if ( ! $has_base_rate ) {
		/**
		 * Filter whether to show the tax configuration incomplete notice.
		 *
		 * @since 10.5.0
		 *
		 * @param bool $show_notice Whether to show the notice. Default true.
		 */
		if ( ! apply_filters( 'woocommerce_show_tax_configuration_notice', true ) ) {
			return;
		}
		?>
		<div class="notice notice-warning">
			<p>
				<strong><?php esc_html_e( 'Tax configuration incomplete', 'woocommerce' ); ?></strong>
			</p>
			<p>
				<?php
				echo wp_kses_post(
					sprintf(
						/* translators: 1: country code, 2: opening link tag, 3: closing link tag */
						__( 'You have enabled "Prices entered with tax" but have not configured a standard tax rate for your base location (%1$s). Please %2$sconfigure standard tax rates%3$s to ensure accurate tax calculations.', 'woocommerce' ),
						esc_html( $base_location['country'] ),
						'<a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=tax&section=standard' ) ) . '">',
						'</a>'
					)
				);
				?>
			</p>
		</div>
		<?php
	}
}