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 | |
add_filter( 'woocommerce_get_order_item_totals', 'wc_get_order_item_totals', 10, 3 ); | |
function wc_get_order_item_totals( $total_rows, $order, $tax_display ) { | |
$total_rows['order_total'] = array( | |
'label' => __( 'Total:', 'woocommerce' ), | |
'value' => $order->get_formatted_order_total(), | |
); | |
return $total_rows; | |
} |
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 | |
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_discount' ); | |
function woocommerce_custom_discount( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
// ADD FLAT RATE DISCOUNT | |
$discount = 5; // Replace 5 with your discount | |
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 | |
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); | |
function woocommerce_custom_surcharge( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
// ADD FLAT RATE FEE | |
$surcharge = 5; // Replace 5 with your fee | |
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 TO CHECK IF SELECTED SHIPPING METHOD IS LOCAL PICKUP | |
function is_local_pickup() { | |
$local_pickup = false; | |
$shipping_method = 'local_pickup:9'; // Replace 9 with your local pickup id | |
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); | |
$chosen_shipping = $chosen_methods[0]; | |
if ($chosen_shipping == $shipping_method) { |
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 | |
// ONLY SHOW FREE SHIPPING METHOD IF AVAILABLE | |
add_filter( 'woocommerce_package_rates', 'only_show_free_shipping', 100 ); | |
function only_show_free_shipping( $rates ) { | |
$free_rates = array(); | |
foreach ( $rates as $rate_id => $rate ) { | |
if ( 'free_shipping' === $rate->method_id ) { | |
$free_rates[ $rate_id ] = $rate; | |
break; |
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 TO CHECK IF ITEM IS IN CART | |
function item_in_cart( $product_id ) { | |
$found = false; | |
if ( sizeof( WC()->cart->get_cart() ) > 0 ) { | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $value ) { | |
$product = $value['data']; | |
if ( $product->get_id() == $product_id ) { | |
$found = true; |
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 | |
// CART | |
add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_shipping_label', 9999, 2 ); | |
function remove_shipping_label( $label, $method ) { | |
$new_label = preg_replace( '/^.+:/', '', $label ); | |
return $new_label; | |
} | |
// ORDER EMAIL |
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 | |
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' ); | |
function change_default_checkout_country() { | |
return 'GB'; | |
} | |
?> |
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 | |
// ADD NEW COUNTRY | |
add_filter( 'woocommerce_countries', 'custom_country_nothern_ireland' ); | |
function custom_country_nothern_ireland( $countries ) { | |
$new_countries = array( 'NIRE' => __( 'Northern Ireland', 'woocommerce' ), ); | |
return array_merge( $countries, $new_countries ); | |
} | |
// ADD NEW COUNTRY UNDER CONTINENT |
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 | |
// DISABLE WOOCOMMERCE SORTING | |
add_filter( 'woocommerce_sort_countries', '__return_false' ); | |
add_filter( 'woocommerce_countries', 'wc_custom_countries_order', 10, 1 ); | |
function wc_custom_countries_order( $countries ) { | |
// Replace with iso code of country AND country name (example: US | United States or GB | United Kingdom (UK) | |
$countries = ['GB' => 'United Kingdom'] + ['US' => 'United States'] + ['CA' => 'Canada'] + $countries; |
NewerOlder