Skip to content

Úprava napojení na Fakturoid účet

Pokud z nějakého důvodu potřebujete programově upravit napojení na Fakturoid účet, můžete využít následující filtr.

apply_filters( 'wpify_woo_fakturoid_client_settings', $client_settings );

Odesílaná data jsou:

$client_settings = array(
'domain' // doména Fakturoid účtu
'email' // přihlašovací email
'client_id' // OAuth2 Client ID
'client_secret' // OAuth2 Client Secret
);
/**
* Edit connection to Fakturoid account
*
* @param array $client_settings Client settings
*
* @return array
*/
function edit_fakturoid_client_settings( $client_settings ): array {
if ( /* vaše podmínka */ ) {
$client_settings['domain'] = 'jiny-ucet';
$client_settings['email'] = 'novy@email.cz';
$client_settings['client_id'] = 'vas_client_id';
$client_settings['client_secret'] = 'vas_client_secret';
}
return $client_settings;
}
add_filter( 'wpify_woo_fakturoid_client_settings', 'edit_fakturoid_client_settings', 10, 1 );

Tento filtr je užitečný například pro napojení na různé Fakturoid účty podle podmínek (např. podle země zákazníka):

/**
* Switch Fakturoid account by customer country
*
* @param array $client_settings Client settings
*
* @return array
*/
function switch_fakturoid_account_by_country( $client_settings ): array {
$order_id = absint( get_query_var( 'order-pay' ) );
if ( $order_id ) {
$order = wc_get_order( $order_id );
if ( $order && $order->get_billing_country() === 'SK' ) {
$client_settings['domain'] = 'slovensky-ucet';
$client_settings['email'] = 'sk@firma.cz';
$client_settings['client_id'] = 'sk_client_id';
$client_settings['client_secret'] = 'sk_client_secret';
}
}
return $client_settings;
}
add_filter( 'wpify_woo_fakturoid_client_settings', 'switch_fakturoid_account_by_country', 10, 1 );

Vlastní funkci lze vložit do tzv. child šablony nebo pomocí pluginu Code Snippets.