• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Display specific shipping method if woocommerce product has specific acf field value

phpwordpresswoocommerceadvanced-custom-fieldsshipping-method


PHP Snippet 1:

 <?php

add_filter( 'woocommerce_package_rates', 'define_default_shipping_method', 10, 2 );
   
function define_default_shipping_method( $rates, $package ) {
$shipping_id = 'table_rate_shipping_first-class';
$colors = get_field('name_of_your_feild');
if( $colors && in_array('cp', $colors) ) {
   unset( $rates[$shipping_id ] ); // you need to unset here other shipping methods
}
     
return $rates;
  
}

?>

Related Snippets

PHP using str_starts_with for array to exclude same as with wildcard

Get Header Authorization value of a login api (sent with username and password in json body) using php curl

Can't exclude directories from .htaccess mobile redirect?

Can't call javascript alert alertify library from PHP

Could not decode a text frame as UTF-8.

PHP array stringify

Check if a string contain multiple specific words

Show only featured products in Woocommerce shop page

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

Filter WooCommerce related products by Polylang language

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

Get all WooCommerce products within own plugin

Submitting a form with ajax in Wordpress

WHERE IN array binding in DB::raw laravel 5.4

Add record for each array elements if missing in table

About Contact Privacy policy Terms and conditions