I 'm creating a custom shipping method for woocommerce. But it can be added to a specific area in the admin area and just fine adjustment settings. But it doesn't appear on the checkout page for some reason and I don't have any clue why. It should be really straight forward and I did that a few times before (pre 3.0)-but I just can't get it to work right now.
Main Class
abstract class Main_Shipping extends WC_Shipping_Method
{
abstract protected function register_shipping($methods);
abstract protected function addActions();
abstract protected function addFilters();
function init()
{
$this->instance_form_fields = include('setting/shipping-settings.php' );
$this->title = $this->get_option('title' );
$this->tax_status = $this->get_option('tax_status');
$this->shipping_price = $this->get_option('shipping_price');
$this->enable_free_shipping = $this->get_option('enable_free_shipping');
$this->free_shipping_total = $this->get_option('free_shipping_total');
$this->init_settings();
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
public function calculate_shipping($package = array())
{
global $woocommerce;
$return_price = $this->shipping_price;
if(!isset($return_price))
{
$return_price = 0;
}
$rate = array(
'id' => $this->id .'_'. $this->instance_id,
'label' => $this->title,
'cost' => $return_price,
);
$this->add_rate( $rate );
}
public function oaship_pickuppoint()
{
ob_start();
?>
<div>
test
</div>
<?php
$sContent = ob_get_clean();
echo $sContent;
}
}
specific GLS carrier Class:
function addActions()
{
add_action('woocommerce_after_shipping_rate', array($this, 'check_choosen_shipping_method') );
}
function addFilters()
{
add_filter('woocommerce_shipping_methods', array($this, 'register_shipping_method'));
}
function register_shipping($methods)
{
$methods['gls_shipping_pickuppoint'] = 'GLS_Shipping_Pickuppoint';
return $methods;
}
function check_choosen_shipping_method($rate)
{
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = preg_replace('/[0-9]+/', '', $chosen_methods[0]);;
if($chosen_shipping === 'gls_shipping_pickuppoint')
{
if ($rate->method_id == 'gls_shipping_pickuppoint') {
$this->oaship_pickuppoint();
}
}
}
}
$oOAGlsPickupPoint = new GLS_Shipping_Pickuppoint();
$oOAGlsPickupPoint->addActions();
$oOAGlsPickupPoint->addFilters();