Created
February 11, 2019 15:18
-
-
Save CrispDev/9177aa63c44ab53f04daf4ee597e849d to your computer and use it in GitHub Desktop.
Autoship Customization // Add Filter to Default Updating a Users existing Autoship Orders with new Address Info.
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
/** | |
* Force all the users autoship orders to be updated if the user | |
* Changes their address info. | |
* | |
* @param bool $update The current update flag. True updates all orders, false doesn't | |
* @param int $user_id The current users id. | |
* | |
* @return bool The filtered update flag. | |
*/ | |
function xx_always_update_my_autoship_scheduled_orders( $update, $user_id ){ | |
// Add custom code here | |
// ex. add a custom "Always apply to my orders" checkbox to user's account | |
// and retieve the value from the user's metadata | |
$should_update = get_user_meta($user_id, 'my_custom_user_field_always_update', true ); | |
return empty( $should_update ) ? $udpate : $should_update; | |
} | |
add_filter('autoship_apply_to_scheduled_orders_by_default', 'xx_always_update_my_autoship_scheduled_orders', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment