Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active February 19, 2019 23:26
Show Gist options
  • Save andrewlimaza/8111d815b03250c8339cf1434b71c0f5 to your computer and use it in GitHub Desktop.
Save andrewlimaza/8111d815b03250c8339cf1434b71c0f5 to your computer and use it in GitHub Desktop.
Offer Free shipping to PMPro Members.
<?php
/**
* If user does not have a membership level only offer flat rate.
* If is a Paid Memberships Pro, force free shipping!
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
*
* PLEASE NOTE: Clear WooCommerce Transients for this to take affect if not working.
* NAVIGATE TO 'WooCommerce' > 'Status' > 'Tools' AND SELECT 'Clear Transients'.
*/
function pmpro_only_show_flat_rate_to_non_members( $rates ) {
if( pmpro_hasMembershipLevel() ){
foreach( $rates as $rate_id => $rate){
if( 'flat_rate' === $rate->method_id ){
unset( $rates[$rate_id] );
}
}
}else{
foreach( $rates as $rate_id => $rate){
if( 'free_shipping' === $rate->method_id ){
unset( $rates[$rate_id] );
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'pmpro_only_show_flat_rate_to_non_members', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment