Created
December 14, 2017 08:19
-
-
Save acanza/945a224deacd8a30c14eb8bc366c9763 to your computer and use it in GitHub Desktop.
Crea una página de agradecimiento personalizada
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
| // Redirige al cliente a una página de agradecimiento personalizada según el producto que haya comprado | |
| if ( in_array( 'woocommerce/woocommerce.php', get_option( 'active_plugins' ) ) && ( version_compare( WC()->version, '3.0.0', '>=' ) ) ){ | |
| add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' ); | |
| function wc_custom_redirect_after_purchase() { | |
| global $wp; | |
| $products_list = array( 17453, 17253 ); // Añade aquí los IDs de tus productos o usa '*' para que se aplique a todos los productos de la tienda | |
| $page_ID = 16089; // Indica aquí el ID de la página de agradecimiento personalizada | |
| if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) { | |
| $order_id = absint( $wp->query_vars['order-received'] ); | |
| $order_key = wc_clean( $_GET['key'] ); | |
| $order = wc_get_order( $order_id ); | |
| $redirect = get_permalink( $page_ID ); | |
| $redirect .= get_option( 'permalink_structure' ) === '' ? '&' : '?'; | |
| $redirect .= 'order=' . $order_id . '&key=' . $order_key; | |
| foreach( $order->get_items() as $item ) { | |
| $_product = wc_get_product( $item['product_id'] ); | |
| if ( in_array( $item['product_id'], $products_list ) || in_array( '*', $products_list ) ) { | |
| wp_redirect( $redirect ); | |
| exit; | |
| } | |
| } | |
| } | |
| } | |
| add_shortcode( 'wc_custom_thank_you_order_review', 'render_wc_custom_thank_you_order_review' ); | |
| function render_wc_custom_thank_you_order_review(){ | |
| $order_review; | |
| // check if the order ID exists | |
| if ( ! isset( $_GET['key'] ) || ! isset( $_GET['order'] ) ) { | |
| return 'Pedido no encontrado'; | |
| } | |
| $order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $_GET['order'] ) ); | |
| $order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) ); | |
| $order = wc_get_order( $order_id ); | |
| if ( $order->get_id() != $order_id || $order->get_order_key() != $order_key ) { | |
| return 'Pedido no encontrado'; | |
| } | |
| ob_start(); | |
| ?> | |
| <div class="woocommerce-order"> | |
| <?php if ( $order ) : ?> | |
| <?php if ( $order->has_status( 'failed' ) ) : ?> | |
| <p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p> | |
| <p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions"> | |
| <a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button pay"><?php _e( 'Pay', 'woocommerce' ) ?></a> | |
| <?php if ( is_user_logged_in() ) : ?> | |
| <a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="button pay"><?php _e( 'My account', 'woocommerce' ); ?></a> | |
| <?php endif; ?> | |
| </p> | |
| <?php else : ?> | |
| <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p> | |
| <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> | |
| <li class="woocommerce-order-overview__order order"> | |
| <?php _e( 'Order number:', 'woocommerce' ); ?> | |
| <strong><?php echo $order->get_order_number(); ?></strong> | |
| </li> | |
| <li class="woocommerce-order-overview__date date"> | |
| <?php _e( 'Date:', 'woocommerce' ); ?> | |
| <strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong> | |
| </li> | |
| <li class="woocommerce-order-overview__total total"> | |
| <?php _e( 'Total:', 'woocommerce' ); ?> | |
| <strong><?php echo $order->get_formatted_order_total(); ?></strong> | |
| </li> | |
| <?php if ( $order->get_payment_method_title() ) : ?> | |
| <li class="woocommerce-order-overview__payment-method method"> | |
| <?php _e( 'Payment method:', 'woocommerce' ); ?> | |
| <strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong> | |
| </li> | |
| <?php endif; ?> | |
| </ul> | |
| <?php endif; ?> | |
| <?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?> | |
| <?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?> | |
| <?php else : ?> | |
| <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p> | |
| <?php endif; ?> | |
| </div> | |
| <?php | |
| $content .= ob_get_contents(); | |
| ob_end_clean(); | |
| return $content; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment