id = 'carrieracct'; $this->method_title = __( 'CarrierAcct Shipping', 'carrieracct' ); $this->method_description = __( 'Custom Shipping Method for CarrierAcct', 'carrieracct' ); $this->init(); $this->enabled = isset( $this->settings['enabled'] ) ? $this->settings['enabled'] : 'no'; $this->title = isset( $this->settings['title'] ) ? $this->settings['title'] : __( 'CarrierAcct Shipping', 'carrieracct' ); } /** * Init your settings * * @access public * @return void */ function init() { // Load the settings API $this->init_form_fields(); $this->init_settings(); // Save settings in admin if you have any defined add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); } /** * Define settings field for this shipping * @return void */ function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable', 'carrieracct' ), 'type' => 'checkbox', 'description' => __( 'Enable this shipping.', 'carrieracct' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'carrieracct' ), 'type' => 'text', 'description' => __( 'Title to be display on site', 'carrieracct' ), 'default' => __( 'CarrierAcct Shipping', 'carrieracct' ) ), ); } /** * This function is used to calculate the shipping cost. Within this function we can check for weights, dimensions and other parameters. * * @access public * @param mixed $package * @return void */ public function calculate_shipping( $package = array( )) { $rate = array( 'id' => $this->id, 'label' => $this->title, 'cost' => '0', 'calc_tax' => 'per_order', 'package' => $package, ); // Register the rate $this->add_rate( $rate ); } } } } add_action( 'woocommerce_shipping_init', 'carrieracct_shipping_method' ); function add_carrieracct_shipping_method( $methods ) { $methods['carrieracct'] = 'CarrierAcct_Shipping_Method'; return $methods; } add_filter( 'woocommerce_shipping_methods', 'add_carrieracct_shipping_method' ); // Add custom fields to a specific selected shipping method add_action( 'woocommerce_after_shipping_rate', 'carrier_custom_fields', 20, 2 ); function carrier_custom_fields( $method, $index ) { if ( ! is_checkout()) return; // Only on checkout page $customer_carrier_method = 'carrieracct'; if ( $method->id != $customer_carrier_method ) return; // Only display for "local_pickup" $chosen_method_id = WC()->session->chosen_shipping_methods[ $index ]; // If the chosen shipping method is 'legacy_local_pickup' we display if ($chosen_method_id == $customer_carrier_method ): echo '
' . get_post_meta( $order->id, '_carrier_name', true ) . ''; echo '' . get_post_meta( $order->id, '_carrier_number', true ) . '
'; ?>