Я хочу автоматически сохранить API ключевые сведения (например, ключ потребителя и секрет) в виде метаполей в учетной записи пользователя, связанной с этим ключом API.
Код: Выделить всё
add_action('woocommerce_api_key_save', 'save_api_key_to_user_meta', 10, 1);
function save_api_key_to_user_meta($key_id) {
// Retrieve the API key details using the key ID
$key = WC()->api->get_key($key_id);
if ($key && !is_wp_error($key)) {
// Get the user ID associated with the API key
$user_id = $key->user_id;
// Save the API key details as user meta, hashing the consumer_secret
update_user_meta($user_id, 'woocommerce_api_key_id', $key_id);
update_user_meta($user_id, 'woocommerce_api_consumer_key', $key->consumer_key);
update_user_meta($user_id, 'woocommerce_api_consumer_secret_hash', wp_hash_password($key->consumer_secret));
update_user_meta($user_id, 'woocommerce_api_key_permissions', $key->permissions);
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... when-an-ap
Мобильная версия