Skip to content

Instantly share code, notes, and snippets.

@2aces
Last active August 31, 2016 21:38
Show Gist options
  • Save 2aces/f4642f5e07851403a00f94e5e304ecb9 to your computer and use it in GitHub Desktop.
Save 2aces/f4642f5e07851403a00f94e5e304ecb9 to your computer and use it in GitHub Desktop.
woocommerce-correios PAC cost filter
/**
* yourprefix_free_shipping_pac function.
* filters Woocommerce Correio's PAC shipping method cost to zero
*
* @access public
* @param array $arr Array with data sent by woocommerce-correios WC_Correios_International_Shipping and WC_Correios_Shipping classes
* @param int $instance_id sent by woocommerce-correios WC_Correios_International_Shipping and WC_Correios_Shipping classe
* @return array
*/
function yourprefix_free_shipping_pac($arr, $instance_id){
$arr['cost'] = 000;
// you may filter by instance_id. For example, to filter only in certain shipping zones
// you find this parameter on shipping zone settings pages (e.g. wp-admin/admin.php?page=wc-settings&tab=shipping&instance_id=5)
// if ( === $instance_id ) {
// $arr['cost'] = 000;
// }
return $arr;
}
add_filter( 'woocommerce_correios_correios-pac_rate', 'yourprefix_free_shipping_pac');
@2aces
Copy link
Author

2aces commented Aug 31, 2016

You can filter other Woocommerce Correios shiping methods by changing 'correios-pac' in filter name for the new methodo id . (e.g. 'correios-carta-registrada', 'correios-sedex-hoje', 'correios-sedex', 'correios-sedex-10-envelope' ).

Example:

function youprefix_sedex_hoje_gratis($arr, $instance_id){
    $arr['cost'] = 000;
    return $arr;
}
add_filter( 'woocommerce_correios_correios-sedex-hoje_rate', 'yourprefix_sedex_hoje_gratis');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment