MultiParcels Shipping For WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the MultiParcels Shipping For WooCommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the MultiParcels Shipping For WooCommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the MultiParcels Shipping For WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
MultiParcels Shipping For WooCommerce

"MultiParcels Shipping For WooCommerce is a seamless plugin designed to simplify your shipping process. It efficiently integrates with WooCommerce to optimize package delivery."

★★★★☆ (59) Active Installs: 3000+ Tested with: 6.2.3 PHP Version: 5.6
Included Shortcodes:
  • [fee]

MultiParcels Shipping For WooCommerce [fee] Shortcode

The ‘fee’ shortcode in the Multiparcels Shipping for WooCommerce plugin calculates shipping fees. It uses attributes like ‘percent’, ‘min_fee’, and ‘max_fee’ to determine the final fee. The ‘percent’ attribute calculates a percentage of the fee cost. The ‘min_fee’ and ‘max_fee’ attributes set the minimum and maximum fee thresholds. The shortcode returns the calculated fee.

Shortcode: [fee]

Parameters

Here is a list of all possible fee shortcode parameters and attributes:

  • percent – Specifies the percentage of the fee cost to be calculated.
  • min_fee – Sets the minimum limit for the calculated fee.
  • max_fee – Establishes the maximum limit for the calculated fee.

Examples and Usage

Basic example – A simple shortcode that calculates the fee based on a given percentage of the cost.

[fee percent=10 /]

Advanced examples

1. Defining a minimum fee – This shortcode calculates the fee based on a given percentage, but will not go below a specified minimum fee.

[fee percent=10 min_fee=5 /]

2. Defining a maximum fee – This shortcode calculates the fee based on a given percentage, but will not exceed a specified maximum fee.

[fee percent=10 max_fee=20 /]

3. Using all parameters – This shortcode calculates the fee based on a given percentage, but will not go below a specified minimum fee or above a specified maximum fee.

[fee percent=10 min_fee=5 max_fee=20 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fee] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'fee', [$this, 'fee']);

Shortcode PHP function:

                    function fee( $atts ) {

            $atts = shortcode_atts(

                [

                    'percent' => '',

                    'min_fee' => '',

                    'max_fee' => '',

                ],

                $atts,

                'fee'

            );



            $calculated_fee = 0;



            if ( $atts['percent'] ) {

                $calculated_fee = $this->fee_cost * ( floatval( $atts['percent'] ) / 100 );

            }



            if ( $atts['min_fee'] && $calculated_fee < $atts['min_fee'] ) {

                $calculated_fee = $atts['min_fee'];

            }



            if ( $atts['max_fee'] && $calculated_fee > $atts['max_fee'] ) {

                $calculated_fee = $atts['max_fee'];

            }



            return $calculated_fee;

        }
                    

Code file location:

multiparcels-shipping-for-woocommerce/multiparcels-shipping-for-woocommerce/includes/abstracts/abstract-wc-mp-shipping-method.php

Conclusion

Now that you’ve learned how to embed the MultiParcels Shipping For WooCommerce Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *