Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check for current product category in single product page (Woocommerce)
<?php
/*
URL: https://wproot.dev/blog/get-woocommerce-current-product-category-single-product-page/
*/
if ( has_term( 'tshirts', 'product_cat' ) ) //product category is tshirts
{
$flatrate = '10.00';
}
elseif ( has_term( 'hoodies', 'product_cat' ) ) //product category is hoodies
{
$flatrate = '15.00';
}
else
{
$flatrate = '0.00';
}
echo 'USD'.$flatrate.' Flat Rate Shipping';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.