Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 10horizons/8388a37ae1a57ac8a1a5a39c51737179 to your computer and use it in GitHub Desktop.
Save 10horizons/8388a37ae1a57ac8a1a5a39c51737179 to your computer and use it in GitHub Desktop.
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