0
Hello. I am creating a shipping method (plugin) where I send the zip code and the cart items and the system (a third party site) returns me the shipping values (PAC and SEDEX). I already implemented a part of the plugin that follows below.
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 showing the freight types to the customer and how to use the function "get_freight()"?! Or some example as a base! From now on, thank you very much.