Created
April 30, 2019 15:31
-
-
Save rayflores/edfcacb6c77171b6f4a7bd840940097b to your computer and use it in GitHub Desktop.
This file contains 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('wc_avatax_order_origin_address', 'verde_change_avatax_order_origin_address', 10, 2 ); | |
// add_filter('wc_avatax_order_destination_address', 'verde_change_avatax_order_origin_address', 10, 2 ); | |
function verde_change_avatax_order_origin_address( $origin_address, $order ){ | |
$origin_address = array(); // empty saved address | |
$branch_id = get_post_meta($order->id, '_avatax_branch_id', true); | |
$branch_address = get_post_meta( $branch_id, 'wpsl_address', true ); | |
$branch_city = get_post_meta( $branch_id, 'wpsl_city', true ); | |
$branch_state = get_post_meta( $branch_id, 'wpsl_state', true ); | |
$branch_postcode = get_post_meta( $branch_id, 'wpsl_zip', true ); | |
$branch_country_iso = get_post_meta( $branch_id, 'wpsl_country_iso', true ); | |
$origin_address = array( | |
'line1' => $branch_address, | |
'city' => $branch_city, | |
'region' => $branch_state, | |
'postalCode' => $branch_postcode, | |
'country' => $branch_country_iso, | |
); | |
return $origin_address; | |
} | |
// change origin address at checkout | |
add_filter('wc_avatax_checkout_origin_address', 'verde_change_avatax_checkout_origin_address', 10, 2 ); | |
// $origin_address = apply_filters( 'wc_avatax_checkout_origin_address', wc_avatax()->get_tax_handler()->get_origin_address(), $cart ); | |
function verde_change_avatax_checkout_origin_address( $origin_address, $cart ){ | |
$origin_address = array(); // empty saved address | |
$branch_id = WC()->session->get('branch_id'); | |
$branch_address = get_post_meta( $branch_id, 'wpsl_address', true ); | |
$branch_city = get_post_meta( $branch_id, 'wpsl_city', true ); | |
$branch_state = get_post_meta( $branch_id, 'wpsl_state', true ); | |
$branch_postcode = get_post_meta( $branch_id, 'wpsl_zip', true ); | |
$branch_country_iso = get_post_meta( $branch_id, 'wpsl_country_iso', true ); | |
$origin_address = array( | |
'line1' => $branch_address, | |
'city' => $branch_city, | |
'region' => $branch_state, | |
'postalCode' => $branch_postcode, | |
'country' => $branch_country_iso, | |
); | |
return $origin_address; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment