Created
July 23, 2020 19:54
-
-
Save hachesilva/db5e0e27102043e52fc3b4899bb032ac to your computer and use it in GitHub Desktop.
Woocommerce add markup to shipping rate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function markup_shipping_rates($rates, $packages) | |
{ | |
$percentage = 5; | |
$cartTotal = WC()->cart->get_totals()['cart_contents_total']; | |
$additionalFee = ($percentage * $cartTotal) / 100; | |
if (isset($rates['enviashipping:1'])) { | |
$initialCost = $rates['enviashipping:1']->cost; | |
$rates['enviashipping:1']->cost = $initialCost + $additionalFee; | |
} | |
return $rates; | |
} | |
add_filter('woocommerce_package_rates', 'markup_shipping_rates', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment