Skip to content

Instantly share code, notes, and snippets.

@rcnascimento
Last active December 12, 2021 03:01
Show Gist options
  • Save rcnascimento/43cab45d3e125606a9ac358c530203f9 to your computer and use it in GitHub Desktop.
Save rcnascimento/43cab45d3e125606a9ac358c530203f9 to your computer and use it in GitHub Desktop.
Utilitário implementando hook do plugin Claudio Sanches – PagSeguro for WooCommerce.
<?php
/**
* Muda o email do comprador para uso da sandbox PagSeguro. Requisito da integração Checkout
* Transparente.
*
* Bypass para o Erro:
* "53122 | sender email invalid domain: {0}. You must use an email @sandbox.pagseguro.com.br".
*
* @param SimpleXMLElement $xml XML completo.
* @param WC_Order $order Dados do Pedido.
*
* @return SimpleXMLElement
*/
function xpto_pagseguro_sandbox_transform_sender_email( $xml, $order ) {
$gateway = wc_get_payment_gateway_by_order( $order );
if ( 'yes' === $gateway->sandbox ) {
list( $local_part ) = explode( '@', $order->get_billing_email() );
$xml_email_node = $xml->xpath( '//sender/email' );
$dom = dom_import_simplexml( $xml_email_node[0] );
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$dom->firstChild->nodeValue = $local_part . '@sandbox.pagseguro.com.br';
}
return $xml;
}
add_filter(
'woocommerce_pagseguro_payment_xml',
'xpto_pagseguro_sandbox_transform_sender_email',
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment