Skip to content

Instantly share code, notes, and snippets.

@Spepe13
Last active February 18, 2021 11:16
Show Gist options
  • Save Spepe13/f631d16304ec0330bce94c60e549fe9e to your computer and use it in GitHub Desktop.
Save Spepe13/f631d16304ec0330bce94c60e549fe9e to your computer and use it in GitHub Desktop.
[Shipping Cost Method] #Wordpress #Woocommerce

Shipping Cost Method

Set the Shipping Cost Method


function swwp_wc_shipping_cost_tiers( $cost, $method ) {

	if ( in_array( $method->get_instance_id(), array( 1, 23 ) ) && WC()->cart ) {

		$cart_item_count = WC()->cart->get_cart_contents_count();

		if ( $cart_item_count > 3 ) {
			$cost = $cost+ ( 1.2 * ($cart_item_count-3) );
		}
	}

	return $cost;
}
add_filter( 'woocommerce_shipping_rate_cost', 'swwp_wc_shipping_cost_tiers', 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment