Skip to content

Hooks and Filters

The WPify Woo Conditional Shipping and Payment plugin provides filters to customize calculations, rules, and behavior of conditional shipping and payment.

wpify_woo_conditional_shipping_cart_amount_include_tax

Section titled “wpify_woo_conditional_shipping_cart_amount_include_tax”

Control whether cart subtotal conditions include or exclude VAT.

apply_filters( 'wpify_woo_conditional_shipping_cart_amount_include_tax', bool $include_tax );

Default: true (cart subtotal includes VAT)

Example — calculate subtotal without VAT:

/**
* Calculate cart subtotal without VAT for shipping conditions
*/
add_filter( 'wpify_woo_conditional_shipping_cart_amount_include_tax', '__return_false' );

wpify_woo_conditional_shipping_cart_total_include_tax

Section titled “wpify_woo_conditional_shipping_cart_total_include_tax”

Control whether cart total conditions include or exclude VAT.

apply_filters( 'wpify_woo_conditional_shipping_cart_total_include_tax', bool $include_tax );

Default: true (cart total includes VAT)

Example — calculate total without VAT:

/**
* Calculate cart total without VAT for shipping conditions
*/
add_filter( 'wpify_woo_conditional_shipping_cart_total_include_tax', '__return_false' );

wpify_woo_conditional_shipping_shipping_adjusted_price

Section titled “wpify_woo_conditional_shipping_shipping_adjusted_price”

Filter the adjusted shipping price before it is applied.

apply_filters( 'wpify_woo_conditional_shipping_shipping_adjusted_price', $value, array $action, array $rule, array $passed_rules );

Parameters:

ParameterTypeDescription
$valuefloatThe adjusted shipping price
$actionarrayThe action configuration
$rulearrayThe rule group that matched
$passed_rulesarrayAll rules that passed conditions

Example — minimum shipping price:

/**
* Set minimum shipping price to 29 CZK
*
* @param float $value Adjusted price
* @param array $action Action
* @param array $rule Rule
* @param array $passed_rules All passed rules
* @return float
*/
function my_minimum_shipping_price( $value, $action, $rule, $passed_rules ) {
return max( $value, 29 );
}
add_filter( 'wpify_woo_conditional_shipping_shipping_adjusted_price', 'my_minimum_shipping_price', 10, 4 );

wpify_woo_conditional_shipping_passed_rules

Section titled “wpify_woo_conditional_shipping_passed_rules”

Filter the rules that passed all conditions before actions are applied.

apply_filters( 'wpify_woo_conditional_shipping_passed_rules', array $rules, string $rules_id, Context $context );

Parameters:

ParameterTypeDescription
$rulesarrayArray of rules that passed all conditions
$rules_idstringIdentifier for the rules set (rules or payment_rules)
$contextContextSource of the evaluated data: the cart, the order on the pay-for-order page, or a product in the Product Shipping API

The filter also runs for the Product Shipping API, where there is no cart — callbacks must not rely on WC()->cart. For a product, the rules are filtered before the “chosen shipping method” conditions are checked.

Example — log rules for debugging:

/**
* Log rules that passed conditions
*
* @param array $rules Rules
* @param string $rules_id Rules set identifier
* @return array
*/
function my_log_passed_rules( $rules, $rules_id ) {
$logger = wc_get_logger();
$logger->debug( sprintf(
'Rules %s: %d rules passed conditions',
$rules_id,
count( $rules )
), [ 'source' => 'conditional-shipping-debug' ] );
return $rules;
}
add_filter( 'wpify_woo_conditional_shipping_passed_rules', 'my_log_passed_rules', 10, 2 );

Set the priority of the woocommerce_package_rates filter hook.

apply_filters( 'wpify_conditional_shipping_rules_priority', int $priority );

Default: 1000

Example — run rules earlier:

/**
* Run shipping rules earlier (lower number = higher priority)
*
* @param int $priority Priority
* @return int
*/
function my_shipping_rules_priority( $priority ) {
return 100;
}
add_filter( 'wpify_conditional_shipping_rules_priority', 'my_shipping_rules_priority' );

wpify_woo_conditional_shipping_enable_negative_fee_fix

Section titled “wpify_woo_conditional_shipping_enable_negative_fee_fix”

Enable or disable the VAT calculation fix for negative fees (discounts).

apply_filters( 'wpify_woo_conditional_shipping_enable_negative_fee_fix', bool $enable );

Default: true

Example — disable the negative fee VAT fix:

/**
* Disable negative fee VAT fix
*/
add_filter( 'wpify_woo_conditional_shipping_enable_negative_fee_fix', '__return_false' );

Filter the shipping rule field definitions. Allows adding custom condition types or modifying existing ones.

apply_filters( 'wpify_woo_conditional_shipping_rules', array $shipping_rules );

wpify_woo_conditional_shipping_payment_rules

Section titled “wpify_woo_conditional_shipping_payment_rules”

Filter the payment rule field definitions.

apply_filters( 'wpify_woo_conditional_shipping_payment_rules', array $payment_rules );

Shipping prices with your rules applied can be calculated for a single product outside the cart — for example to show the shipping price on the product page or to export it to a product feed. The calculation uses the WooCommerce shipping methods of the matching zone (including free shipping with a minimum order amount), applies the shipping rules and never reads or changes the customer’s cart or session.

Get the module from the plugin container:

$module = wpify_woo_conditional_shipping_container()->get( \WpifyWooConditionalShipping\Modules\WpifyWooConditionalShipping\WpifyWooConditionalShippingModule::class );
MethodReturns
get_product_shipping_rates( WC_Product $product, array $args = [] )WC_Shipping_Rate[] keyed by rate ID (e.g. flat_rate:4). A method hidden by a rule or not available for the product is missing.
get_products_shipping_rates( WC_Product[] $products, array $args = [] )Rates for many products at once, keyed by product ID. Use it for feeds — it loads the product terms in one query.
get_product_payment_fees( WC_Product $product, array $args = [] )Fees from the payment rules for $args['payment']: [ [ 'label' => string, 'amount' => float, 'tax' => float ] ].
get_rate_total( WC_Shipping_Rate $rate )Rate price including VAT (float).

A variable product is calculated for its default variation when it is in stock, otherwise for the cheapest variation in stock. A virtual product has no rates.

KeyTypeDefaultDescription
countrystringcustomer’s shipping country, otherwise the store countryDestination country (ISO code, e.g. CZ)
state, postcodestringas countryDestination state and postcode
quantityint1Number of pieces of the product
paymentstringnonePayment gateway ID for payment conditions and fees (e.g. cod)
shippingstringnoneRate ID counted as the chosen shipping for payment rules with a shipping condition (fees only)
userWP_User|int|nulllogged-in userUser for role conditions. Pass null in feeds and cron jobs.
methodsint[]all methods of the zoneLimit the calculation to these shipping method instance IDs

Conditions that need a cart are evaluated for the product alone: cart amount and total = product price × quantity, no coupons, and a “chosen shipping method” condition counts the rate being calculated as the chosen one.

Example — shipping prices on the product page:

/**
* Show shipping prices under the product summary
*/
function my_product_shipping_prices() {
global $product;
if ( ! function_exists( 'wpify_woo_conditional_shipping_container' ) || ! $product ) {
return;
}
$module = wpify_woo_conditional_shipping_container()->get( \WpifyWooConditionalShipping\Modules\WpifyWooConditionalShipping\WpifyWooConditionalShippingModule::class );
foreach ( $module->get_product_shipping_rates( $product ) as $rate ) {
printf( '<p>%s: %s</p>', esc_html( $rate->get_label() ), wc_price( $module->get_rate_total( $rate ) ) );
}
}
add_action( 'woocommerce_single_product_summary', 'my_product_shipping_prices', 25 );

Example — cash on delivery price for a feed:

$args = [ 'country' => 'CZ', 'methods' => [ 4 ], 'user' => null ];
$rates = $module->get_products_shipping_rates( $products, $args );
foreach ( $products as $product ) {
$rate = $rates[ $product->get_id() ]['flat_rate:4'] ?? null;
if ( ! $rate ) {
continue; // Method not available for this product.
}
$price = $module->get_rate_total( $rate );
$fees = $module->get_product_payment_fees( $product, $args + [ 'payment' => 'cod', 'shipping' => 'flat_rate:4' ] );
$cod = $price + array_sum( array_map( fn( $fee ) => $fee['amount'] + $fee['tax'], $fees ) );
}

wpify_woo_conditional_shipping_product_rate_methods

Section titled “wpify_woo_conditional_shipping_product_rate_methods”

Filter the shipping methods used for the product calculation. Use it to leave out a method that cannot be calculated outside the cart (e.g. a carrier that calls an external API).

apply_filters( 'wpify_woo_conditional_shipping_product_rate_methods', WC_Shipping_Method[] $methods, WC_Product $product, array $args );

Example — leave out a carrier:

function my_product_rate_methods( $methods, $product, $args ) {
return array_filter( $methods, fn( $method ) => 'my_carrier' !== $method->id );
}
add_filter( 'wpify_woo_conditional_shipping_product_rate_methods', 'my_product_rate_methods', 10, 3 );

wpify_woo_conditional_shipping_product_base_rates

Section titled “wpify_woo_conditional_shipping_product_base_rates”

Filter the WooCommerce rates of a product before the shipping rules are applied. Multi-currency plugins (e.g. WCML) convert shipping prices only in the cart, so a currency conversion for the product calculation belongs here. The callback must return WC_Shipping_Rate objects.

apply_filters( 'wpify_woo_conditional_shipping_product_base_rates', WC_Shipping_Rate[] $rates, WC_Product $product, array $args );

A shipping method that throws an exception is skipped, and taxes are always calculated from the product — a method’s own taxes are not used.

You can add custom functions either in your child theme’s functions.php or use the Code Snippets plugin.