Added new filters when adding shipping rates

Ref. https://github.com/woocommerce/woocommerce/issues/20632
This commit is contained in:
Diego Zanella 2018-06-26 20:15:54 +01:00
parent d394dec5f2
commit 25817b9236
1 changed files with 5 additions and 4 deletions

View File

@ -263,7 +263,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
* @param array $args Arguments (default: array()). * @param array $args Arguments (default: array()).
*/ */
public function add_rate( $args = array() ) { public function add_rate( $args = array() ) {
$args = wp_parse_args( $args, array( $args = apply_filters( 'woocommerce_shipping_add_rate_args', wp_parse_args( $args, array(
'id' => $this->get_rate_id(), // ID for the rate. If not passed, this id:instance default will be used. 'id' => $this->get_rate_id(), // ID for the rate. If not passed, this id:instance default will be used.
'label' => '', // Label for the rate. 'label' => '', // Label for the rate.
'cost' => '0', // Amount or array of costs (per item shipping). 'cost' => '0', // Amount or array of costs (per item shipping).
@ -271,7 +271,8 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
'calc_tax' => 'per_order', // Calc tax per_order or per_item. Per item needs an array of costs. 'calc_tax' => 'per_order', // Calc tax per_order or per_item. Per item needs an array of costs.
'meta_data' => array(), // Array of misc meta data to store along with this rate - key value pairs. 'meta_data' => array(), // Array of misc meta data to store along with this rate - key value pairs.
'package' => false, // Package array this rate was generated for @since 2.6.0. 'package' => false, // Package array this rate was generated for @since 2.6.0.
) ); 'price_decimals' => wc_get_price_decimals(),
), $this ) );
// ID and label are required. // ID and label are required.
if ( ! $args['id'] || ! $args['label'] ) { if ( ! $args['id'] || ! $args['label'] ) {
@ -288,7 +289,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
} }
// Round the total cost after taxes have been calculated. // Round the total cost after taxes have been calculated.
$total_cost = wc_format_decimal( $total_cost, wc_get_price_decimals() ); $total_cost = wc_format_decimal( $total_cost, $args['price_decimals'] );
// Create rate object. // Create rate object.
$rate = new WC_Shipping_Rate(); $rate = new WC_Shipping_Rate();
@ -315,7 +316,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
$rate->add_meta_data( __( 'Items', 'woocommerce' ), implode( ', ', $items_in_package ) ); $rate->add_meta_data( __( 'Items', 'woocommerce' ), implode( ', ', $items_in_package ) );
} }
$this->rates[ $args['id'] ] = $rate; $this->rates[ $args['id'] ] = apply_filters( 'woocommerce_shipping_add_rate', $rate, $args, $this );
} }
/** /**