• 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

Exact alternate to mcrypt_encrypt in PHP 7.2

Combine multiple columns into an array as one of the key in a results set

Add a custom text for a particular product on specific email notification in Woocommerce

merging two arrays with specified index

carbon generated datetime not stored correctly into the database

Laravel phpunit test failing authorization

PHP header location absolute URL

WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

How To Access A Column In M-M Relationship Table In Laravel

woocommerce_wp_select options array from product attribute terms

XML to CSV with PHP converter [problem with images grabing]

Post Form Data To phpmyadmin Database

wordpress function breaks wp-admin

Get all WooCommerce products within own plugin

How to loop sql table data inside a html table

About Contact Privacy policy Terms and conditions