AI Verified

Name

WooCommerce Shipping Method Button

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

FP---Codevault

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://frankpurcell.co.za

History

Last modified:

01/02/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WooCommerce Shipping Method Button

 
                    
1// Register new shipping method
2add_action( 'woocommerce_shipping_init', 'custom_shipping_method_init' );
3function custom_shipping_method_init() {
4 if ( ! class_exists( 'WC_Request_Shipping_Quote' ) ) {
5 class WC_Request_Shipping_Quote extends WC_Shipping_Method {
6 
7 /**
8 * Constructor for your shipping class
9 *
10 * @access public
11 * @return void
12 */
13 public function __construct() {
14 $this->id = 'request_shipping_quote';
15 $this->method_title = __( 'International Shipping Quote' );
16 $this->method_description = __( 'Allow customers who match the zone to receive a shipping cost before making payment.' );
17 $this->enabled = "yes";
18 $this->title = "Request Shipping Quote";
19 $this->tax_status = 'none';
20 $this->init();
21 }
22 
23 /**
24 * Init your settings
25 *
26 * @access public
27 * @return void
28 */
29 function init() {
30 // Load the settings API
31 $this->init_form_fields();
32 $this->init_settings();
33 // Save settings in admin if you have any defined
34 add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
35 }
36 
37 /**
38 * calculate_shipping function.
39 *
40 * @access public
41 * @param mixed $package
42 * @return void
43 */
44 public function calculate_shipping( $package ) {
45 $rate = array(
46 'id' => $this->id,
47 'label' => $this->title,
48 'cost' => 0,
49 'calc_tax' => 'per_item'
50 );
51 // Register the rate
52 $this->add_rate( $rate );
53 }
54 }
55 }
56}
57 
58// Add the shipping method to WooCommerce
59add_filter( 'woocommerce_shipping_methods', 'add_request_shipping_quote_method' );
60function add_request_shipping_quote_method( $methods ) {
61 $methods['request_shipping_quote'] = 'WC_Request_Shipping_Quote';
62 return $methods;
63}
64 
65// Change "Request Shipping Quote" to a button
66add_filter( 'woocommerce_cart_shipping_method_full_label', 'custom_shipping_request_quote_label', 10, 2 );
67function custom_shipping_request_quote_label( $label, $method ) {
68 if ( $method->method_id == 'request_shipping_quote' ) {
69 $label = '<button type="button" class="button">Request Shipping Quote</button>';
70 }
71 return $label;
72}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

WooCommerce Show Custom Content Above Product Name

Added: 1 year ago

Last Updated: 1 year ago

This quick guide shows you how to display custom content above the product title on the single product template using the woocommerce_single_product_summary hook. You may need to tweak the priority nu...

WooCommerce

AI Verified

0

Set Tax status as none by default when creating a new product

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce Add Custom Content To The Bottom Of The Order Received Thank You Page

Added: 1 year ago

Last Updated: 1 year ago

Adding custom content at the bottom of the the WooCommerce Order Received Thank You page is a great way to sell upsell products, ask users to rate your store, capture permission for email subscription...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

WooCommerce Shipping Method Button

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce - My Account - Edit Address - Fix

Added: 1 year ago

Last Updated: 1 year ago

Fixes the issue with the "Edit Address" text missing from the user's My Account menu. This happens due to a language conflict when using English (South African/US), however using English (UK) also res...

WooCommerce

AI Verified

0

Set Username based on Email - WooCommerce

Added: 1 year ago

Last Updated: 8 months ago

This code adds a filter to the WooCommerce new customer data, so that the user login is automatically set to the user's email address.