Created
August 19, 2013 19:53
-
-
Save sajidzaman/6273318 to your computer and use it in GitHub Desktop.
If you want to update billing information as well on update cart button.
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
remove_action('init', 'woocommerce_update_cart_action'); //Remove cart update action so that billing address will be updated | |
add_action('init','woocommerce_update_billing'); //Hook own function to update billing address on cart update | |
function woocommerce_update_billing(){ | |
global $woocommerce; | |
if(! empty( $_POST['update_cart'] ) && $woocommerce->verify_nonce('cart')) { | |
$customer_id = get_current_user_id(); | |
$billing_data['billing_first_name' ] = $_POST['billing_first_name' ]; | |
$billing_data['billing_last_name' ] = $_POST['billing_last_name' ]; | |
$billing_data['billing_phone' ] = $_POST['billing_phone' ]; | |
$billing_data['billing_email' ] = $_POST['billing_email' ]; | |
$billing_data['billing_cost' ] = $_POST['billing_cost' ]; | |
$billing_data['billing_branch' ] = $_POST['billing_branch' ]; | |
$billing_data['billing_company' ] = $_POST['billing_company' ]; | |
$billing_data['billing_attention' ] = $_POST['billing_attention' ]; | |
$billing_data['billing_address_1' ] = $_POST['billing_address_1' ]; | |
$billing_data['billing_address_2' ] = $_POST['billing_address_2' ]; | |
$billing_data['billing_city' ] = $_POST['billing_city' ]; | |
$billing_data['billing_state' ] = $_POST['billing_state' ]; | |
$billing_data['billing_postcode' ] = $_POST['billing_postcode' ]; | |
$billing_data['billing_country' ] = $_POST['billing_country' ]; | |
$billing_data['billing_date' ] = $_POST['billing_date' ]; | |
$billing_data['billing_needed' ] = $_POST['billing_needed' ]; | |
$billing_data['payment_method' ] = $_POST['payment_method' ]; | |
$billing_data['billing_country' ] = $_POST['billing_country' ]; | |
If($customer_id){ | |
foreach ( $billing_data as $key => $field ) { | |
update_user_meta( $customer_id, $key, $field ); //Add billing data in user meta table | |
} | |
} | |
} | |
} | |
add_action('init', 'woocommerce_update_cart_action'); //Hook update cart function again after the billing data update. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment