1

algún hook que me permita finalizar automáticamente el proceso de finalizar pedido del formulario checkout después de un pago exitoso con tarjeta de crédito, uso un plugin de gateway que no he desarrollado, opera el pago pero confunde el comprador y no le da en el botón finalizar pedido.

1
  • Desconozco wooComerce, pero creo que el flujo debe ser diferente, es decir, finalizas el pedido (lo guardas en base de datos), realizas el proceso de pago y, si todo salió bien, lo marcas como pagado.
    – Triby
    Commented el 3 jun. 2020 a las 21:47

1 respuesta 1

0

Te dejo un template modelo para engancharse a los cambios en el procesamiento de las ordenes. Basado en un tutorial de Matt Lowe, el primer bloque y el último están para darle colores por consola al debug de wordpress.

Pareciera que woocommerce_payment_complete es el action que te puede servir, pero mejor fijate el debug cómo es el ciclo y donde te convenga mas.

<?php
/* MISC log */
define( 'DG_LOG_TEXT_WHITE' , "\033[0m" );
define( 'DG_LOG_TEXT_GREEN' , "\033[32m" );
define( 'DG_LOG_TEXT_RED' , "\033[31m" );
define( 'DG_LOG_TEXT_MAGENTA' , "\033[35m" );
define( 'DG_LOG_TEXT_CYAN' , "\033[36m" );
define( 'DG_LOG_TEXT_YELLOW' , "\033[33m" );

define( 'DG_LOG_TRUE' , DG_LOG_TEXT_GREEN . 'TRUE' . DG_LOG_TEXT_WHITE );
define( 'DG_LOG_FALSE' , DG_LOG_TEXT_RED . 'FALSE' . DG_LOG_TEXT_WHITE );

define( 'DG_LOG_ACTION_PRIORITY', 5 );
// https://squelchdesign.com/web-design-newbury/woocommerce-detecting-order-complete-on-order-completion/

/* payments */
add_action(
  'woocommerce_payment_complete',
  'DG_WC_ACTIONS_WC_payment_complete',
  DG_LOG_ACTION_PRIORITY, 1
);

function DG_WC_ACTIONS_WC_payment_complete( $order_id ) {
  write_log(
    DG_LOG_TEXT_GREEN .
    "Payment has been received for order {$order_id}" .
    DG_LOG_TEXT_WHITE
  );
}

/* orders */
add_action(
  'woocommerce_order_status_pending',
  'DG_WC_ACTIONS_WC_order_pending',
  DG_LOG_ACTION_PRIORITY, 1
);
add_action(
  'woocommerce_order_status_failed',
  'DG_WC_ACTIONS_WC_order_failed',
  DG_LOG_ACTION_PRIORITY, 1
);
add_action(
  'woocommerce_order_status_on-hold',
  'DG_WC_ACTIONS_WC_order_hold',
  DG_LOG_ACTION_PRIORITY, 1
);
/* Note that it's woocommerce_order_status_on-hold, and NOT on_hold.*/
add_action(
  'woocommerce_order_status_processing',
  'DG_WC_ACTIONS_WC_order_processing',
  DG_LOG_ACTION_PRIORITY, 1
);
add_action(
  'woocommerce_order_status_completed',
  'DG_WC_ACTIONS_WC_order_completed',
  DG_LOG_ACTION_PRIORITY, 1
);
add_action(
  'woocommerce_order_status_refunded',
  'DG_WC_ACTIONS_WC_order_refunded',
  DG_LOG_ACTION_PRIORITY, 1
);
add_action(
  'woocommerce_order_status_cancelled',
  'DG_WC_ACTIONS_WC_order_cancelled',
  DG_LOG_ACTION_PRIORITY, 1
);

function DG_WC_ACTIONS_WC_order_pending( $order_id ) {
  write_log( DG_LOG_TEXT_YELLOW . "{$order_id} set to PENDING" . DG_LOG_TEXT_WHITE );
}
function DG_WC_ACTIONS_WC_order_failed( $order_id ) {
  write_log( DG_LOG_TEXT_RED . "{$order_id} set to FAILED" . DG_LOG_TEXT_WHITE );
}
function DG_WC_ACTIONS_WC_order_hold( $order_id ) {
  write_log( DG_LOG_TEXT_MAGENTA . "{$order_id} set to ON HOLD" . DG_LOG_TEXT_WHITE );
}

function DG_WC_ACTIONS_WC_order_processing( $order_id ) {
  write_log( DG_LOG_TEXT_CYAN . "{$order_id} set to PROCESSING" . DG_LOG_TEXT_WHITE );
}

function DG_WC_ACTIONS_WC_order_completed( $order_id ) {
  write_log( DG_LOG_TEXT_GREEN . "{$order_id} set to COMPLETED" . DG_LOG_TEXT_WHITE );
}

function DG_WC_ACTIONS_WC_order_refunded( $order_id ) {
  write_log( DG_LOG_TEXT_MAGENTA . "{$order_id} set to REFUNDED" . DG_LOG_TEXT_WHITE );
}
function DG_WC_ACTIONS_WC_order_cancelled( $order_id ) {
  write_log(  DG_LOG_TEXT_RED . "{$order_id} set to CANCELLED" . DG_LOG_TEXT_WHITE );
}


// https://wordpress.stackexchange.com/a/260309/62765
if (!function_exists('write_log')) {
  function write_log($log) {
    if (true === WP_DEBUG) {
      if (is_array($log) || is_object($log)) {
        error_log(print_r($log, true));
      } else {
        error_log($log);
      }
    }
  }
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.