Home / eCommerce / Set Default Tax Class to ‘Zero rate’ on WC Vendors Pro Add Product Form
Duplicate Snippet

Embed Snippet on Your Site

Set Default Tax Class to ‘Zero rate’ on WC Vendors Pro Add Product Form

Code Preview
php
<?php
/**
 * Set Default Tax Class to 'Zero rate' on WC Vendors Pro Add Product Form
 */
add_filter( 'wcv_product_tax_class', 'custom_wcv_default_product_tax_class', 10, 1 );
function custom_wcv_default_product_tax_class( $args ) {
	// Check if editing a product (post ID exists) or creating a new one
	$product_id = get_the_ID();
	// If $args is an array (Pro Form Builder definition)
	if ( is_array( $args ) ) {
		if ( ! $product_id || get_post_type( $product_id ) !== 'product' ) {
			$args['value'] = 'zero-rate'; // Set default slug for new products
		}
		return $args;
	}
	// Fallback for non-array string values when creating a new product
	if ( empty( $args ) && ! $product_id ) {
		return 'zero-rate';
	}
	return $args;
}
/**
 * Set Default Tax Status on WC Vendors Pro Add Product Form (Optional)
 */
add_filter( 'wcv_product_tax_status', 'custom_wcv_default_product_tax_status', 10, 1 );
function custom_wcv_default_product_tax_status( $args ) {
	$product_id = get_the_ID();
	if ( is_array( $args ) ) {
		if ( ! $product_id || get_post_type( $product_id ) !== 'product' ) {
			$args['value'] = 'none'; // Set 'none' or 'taxable'
		}
		return $args;
	}
	if ( empty( $args ) && ! $product_id ) {
		return 'none';
	}
	return $args;
}

Comments

Add a Comment