Skip to content

Charge a different tax rate on some products

Sunshine picks one tax rate for the whole order, based on the customer's address. Some places tax certain products at a different rate than others, like a lower rate on prints than on digital files. A short code snippet lets you give those products their own rate.

Requires Sunshine Photo Cart 3.7.3 or newer. The snippets below do nothing on older versions.

Before You Add the Snippet

Set up your normal rate first in Sunshine > Settings > Taxes, the same way you would without the snippet. See Setting Up Taxes if you haven't done this yet.

The snippet only changes the rate for the products you choose. Everything else keeps your normal rate. The products you choose also need Taxable checked on the product, just like any other taxed product.

Option 1: Change the Rate for a Product Type

This is the easiest option when a whole type of product gets a different rate, like all prints. New products of that type are covered as soon as you add them, so you never need to edit the snippet again.

add_filter( 'sunshine_cart_item_tax_rate', function( $tax_rate, $cart_item ) {
    if ( ! empty( $tax_rate ) && 'print' === $cart_item->get_type() ) {
        $tax_rate['rate'] = 0.05; // 5% rate.
    }
    return $tax_rate;
}, 10, 2 );

Learn how to add this custom code to your WordPress website

Change 0.05 to the rate you want, written as a decimal: 5% is 0.05, 12% is 0.12.

To use a different product type, change 'print' to one of these:

  • print: Print (this includes canvases, wall art and anything else set up as a Print)
  • download: Digital Download
  • package: Package
  • multi-image: Multi-image
  • general: General (from Sell Anything)
  • session-fee: Session Fee

Option 2: Change the Rate for Specific Products

Use this option when only some products get a different rate, like fine art prints but not standard prints. List the IDs of those products in the snippet.

add_filter( 'sunshine_cart_item_tax_rate', function( $tax_rate, $cart_item ) {
    $different_rate_products = array( 123, 456, 789 ); // Your product IDs go here.
    if ( ! empty( $tax_rate ) && in_array( $cart_item->get_product_id(), $different_rate_products ) ) {
        $tax_rate['rate'] = 0.05; // 5% rate.
    }
    return $tax_rate;
}, 10, 2 );

Learn how to add this custom code to your WordPress website

Replace 123, 456, 789 with your own product IDs, separated by commas. You can learn how to find the product ID here.

Remember to add the ID to the snippet whenever you create a new product that should get a different rate.

How It Works

When a customer's address matches one of your tax rates, each item in the cart gets its tax from that rate, unless the snippet changes it. Each item is saved on the order with the tax for its own rate, and the order's total tax adds them together.

If the customer's address doesn't match any of your tax rates, no tax is charged and the snippet makes no change.

Shipping keeps your normal rate.

Things to Know

  • Discount codes on the whole order work out their tax at your normal rate, even when the order has items at a different rate in it. Discounts on single items are fine.
  • Stripe's "Redirect to Stripe Checkout" mode sends Stripe one tax rate for the whole order, so Stripe's receipt and tax reports won't match the order. Use the Inline Payment Form mode if you use this snippet.
  • Gallery prices shown with tax: if your prices don't include tax and you show prices with tax added in galleries, those gallery prices use your normal rate. The cart and checkout show the correct amount.

Still need help?

If you have not yet found your answer in the documentation articles, please contact support

Sunshine Photo Cart for WordPress