Last active
May 26, 2025 16:19
-
-
Save joseconti/fdb4ea3ab05590aca1f7e7d333727570 to your computer and use it in GitHub Desktop.
Marcar los pedidos como pagados vía parámentros en la URL si falla el código del plugon
This file contains hidden or 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
<?php | |
add_action( 'wp_head', 'redsys_force_mark_order_as_paid_on_thankyou_page_2' ); | |
/** | |
* Force mark order as paid on thank you page. | |
* | |
* @return void | |
*/ | |
function redsys_force_mark_order_as_paid_on_thankyou_page_2() { | |
if ( isset( $_GET['key'], $_GET['Ds_MerchantParameters'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
$order_key = sanitize_text_field( wp_unslash( $_GET['key'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
$order_id = wc_get_order_id_by_order_key( $order_key ); | |
if ( $order_id && is_numeric( $order_id ) ) { | |
sleep( 5 ); | |
$is_redsys_order = WCRed()->is_redsys_order( $order_id ); | |
$is_paid = WCRed()->is_paid( $order_id ); | |
$order = wc_get_order( $order_id ); | |
if ( ( $order && $is_redsys_order && ! $is_paid ) || WCRed()->is_payment_method_change_order( $order_id ) ) { | |
// Check the Redsys URL. | |
if ( isset( $_GET['Ds_MerchantParameters'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
$params = array( | |
'Ds_MerchantParameters' => sanitize_text_field( wp_unslash( $_GET['Ds_MerchantParameters'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
'Ds_Signature' => isset( $_GET['Ds_Signature'] ) ? sanitize_text_field( wp_unslash( $_GET['Ds_Signature'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
); | |
$payment_method = $order->get_payment_method(); | |
$payment_gateway = WC_Payment_Gateways::instance()->payment_gateways()[ $payment_method ]; | |
if ( $payment_gateway && method_exists( $payment_gateway, 'successful_request' ) ) { | |
$payment_gateway->successful_request( $params ); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use this code if you’re using my WooCommerce Redsys Gateway plugin by placing it in your theme’s functions.php file or in a snippets plugin like Code Snippets.