Hello. I am creating a method of sending (plugin) where I send the zip and cart items and the system (a third party site) returns me the values of the freight (PAC and SEDEX). I have already implemented a part of the plugin that follows.
function get_fretes($cep, $itens_carrinho){
// RETURNA OS VALORES DOS FRETES: PAC, SEDEX e ETCs
return $fretes;
}
function metodo_envio_teste_init() {
if ( ! class_exists( 'WC_TESTE_PAC' ) ) {
class WC_TESTE_PAC extends WC_Shipping_Method {
public function __construct() {
$this->id = 'teste_pac';
$this->title = __( 'PAC' );
$this->method_description = __( 'Método usado pelo fornecedor, calculado diretamente!' ); //
$this->enabled = 'yes';
}
public function is_available( $package ){
// Verifica se o cliente digitou o cep
if(empty(WC()->customer->get_shipping_postcode()))
return false;
else
return true;
}
public function calculate_shipping( $package = Array() ) {
$rate = array(
'id' => $this->id,
'label' => "PAC",
'cost' => '50'
);
$this->add_rate( $rate );
}
}
}
}
add_action( 'woocommerce_shipping_init', 'metodo_envio_teste_init' );
function add_metodo_envio_teste( $methods ) {
$methods[] = 'WC_TESTE_PAC';
return $methods;
}
add_filter( 'woocommerce_shipping_methods', 'add_metodo_envio_teste' );
I need help on how to show customer freight rates and how to use the "get_fretes ()" function ?! Or some example as a basis! Thanks in advance.