• 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

How to prevent phpmailer sending embedded image as an attachment on Gmail?

Is it possible to re-use an array taken from PHP via JSON in a $.ajax function?

How to put php code inside opening and closing shortcodes

oauth-private.key does not exist or is not readable

Inserting Country Selection into MySQL PHP [duplicate]

How to get the ID of the link in another page in php

Could not decode a text frame as UTF-8.

Login if user is active using Laravel Breeze

Call to a member function givePermissionTo() on null

Laravel MSSQL Server Connection not working

I want a way to give path to my files which are outside of public folder in laravel

api response laravel doesn't show

Post Form Data To phpmyadmin Database

Converting IPv6 to IPv4 address in PHP

WooCommerce Additional Information - if empty, hide

About Contact Privacy policy Terms and conditions