woocommerce_(id)_shipping_add_rate хук-событиеWC 1.0

Developers can add additional flat rates based on this one via this action since @version 2.4.

Previously there were (overly complex) options to add additional rates however this was not user. friendly and goes against what Flat Rate Shipping was originally intended for.

Использование

add_action( 'woocommerce_(id)_shipping_add_rate', 'wp_kama_woocommerce_id_shipping_add_rate_action', 10, 2 );

/**
 * Function for `woocommerce_(id)_shipping_add_rate` action-hook.
 * 
 * @param  $that 
 * @param  $rate 
 *
 * @return void
 */
function wp_kama_woocommerce_id_shipping_add_rate_action( $that, $rate ){

	// action...
}
$that
-
$rate
-

Где вызывается хук

WC_Shipping_Flat_Rate::calculate_shipping()
woocommerce_(id)_shipping_add_rate
woocommerce/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php 230
do_action( 'woocommerce_' . $this->id . '_shipping_add_rate', $this, $rate );

Где используется хук в WooCommerce

woocommerce/includes/shipping/legacy-flat-rate/class-wc-shipping-legacy-flat-rate.php 63
add_action( 'woocommerce_flat_rate_shipping_add_rate', array( $this, 'calculate_extra_shipping' ), 10, 2 );