• 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

Confirm Leave on External Links in Wordpress

PHP mail function is sending blank message body

Star and Half Star Rating in Laravel

Merge column values from two arrays to form an indexed array of associative arrays

How to validate Envato Purchase Code in PHP

Woocommerce Checkout - Add conditional field required if one field is filled

Call to a member function fetch_field() on a non-object MySQLiDB

How to loop sql table data inside a html table

PHP and WebView - Cookie doesn't are the same

How to convert the int value to inch in PHP [closed]

PHP each() function replacement

how to redirect the user back to desired URL after login page in PHP?

Creating a config file in PHP

How to skip cart page on woocomerce for certain products only?

How can I get user id from session in javascript?

About Contact Privacy policy Terms and conditions