Category: Uncategorized

Show Woocommerce shipping based on product category

function cart_has_product_with_new_cats() {
//Check to see if user has product in cart
global $woocommerce;
//assigns a default negative value
// categories targeted 17, 18, 19

$product_in_cart = false;

// start of the loop that fetches the cart items

foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values[‘data’];
$terms = get_the_terms( $_product->id, ‘product_cat’ );

// second level loop search, in case some items have several categories
foreach ($terms as $term) {
$_categoryid = $term->term_id;
}

if ( $_categoryid === 94 ) {
$product_in_cart = true;
}

}

return $product_in_cart;
}

// add filter and function to hide method
add_filter( ‘woocommerce_package_rates’, ‘hide_shipping_if_cat_is_orange’ , 10, 2 );
function hide_shipping_if_cat_is_orange( $rates, $package ){
if ( cart_has_product_with_new_cats() ) {
// remove the rate you want
unset( $rates[‘wf_shipping_canada_post:DOM.RP’] );
}else{
unset( $rates[‘1’] );
}

// return the available methods without the one you unset.
return $rates;
}

Advertisements

blocked css by CORS policy

has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin is therefore not allowed access.
<IfModule mod_headers.c>
  <FilesMatch “\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$”>
    Header set AccessControlAllowOrigin “*”
  </FilesMatch>
</IfModule>