• 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

Insert a DIV after the 6th product only once in WooCommerce category archives

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

Unable to run composer install

"cannot list resources" error from WooCommerce REST API

PHP drop down list using array's and foreach (else and for) code

Losing session data after POST from third party website

How to validate tin and cst using PHP?

Xdebug in Laravel is not working with VSCode

PHP Find Array Index value in multi-line array

How to change the app environment at run time?

Group rows by column and sum another column within groups [duplicate]

Reload parent page after submit in iframe

Apply filter array/return terms

Get WooCommerce product variation attribute terms in admin products general box

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

About Contact Privacy policy Terms and conditions