Skip to content

Instantly share code, notes, and snippets.

@nagygabor
Created October 24, 2018 18:39
Show Gist options
  • Save nagygabor/cc45cb2de911ec3efcee4c465257c96b to your computer and use it in GitHub Desktop.
Save nagygabor/cc45cb2de911ec3efcee4c465257c96b to your computer and use it in GitHub Desktop.
Megrendelés köszönöm oldal generálás shortcode-al
//Usage: [woothankyouform default='Hibás megrendelésszám!']
function xnagyg_woocommerce_thankyou( $atts ) {
extract( shortcode_atts( array(
'default' => '',
), $atts ) );
//Must remove action because of infinite redirect loop. checkout/thankyou.php template would call it again
remove_action('woocommerce_thankyou','xnagyg_thankyouredirect',1);
// Check if the order ID exists.
if ( empty( $_GET['key'] ) || empty( $_GET['order'] ) ) {
return $default; //Not an order
}
wc_print_notices();
$order = false;
$order_id = absint( apply_filters( 'woocommerce_thankyou_order_id', absint( $_GET['order'] ) ) );
$order_key = wc_clean( apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) ) );
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
//Not valid order_id
if ( false === $order ) {
return $default;
}
//Not valid key for this order
if ( $order->get_order_key() !== $order_key ) {
$order = false;
return $default;
}
}
// Empty awaiting payment session.
unset( WC()->session->order_awaiting_payment );
// Empty current cart.
wc_empty_cart();
//Template execution
ob_start();
wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
//TODO: az átutalás banki adatai nem töltődnek ki...
//Megrendelő adatok csak azonos bejelentkezett felhasználó esetén látszódik, ha nincs bejelentkezve, akkor tegyük ki:
if (!(is_user_logged_in() && $order->get_user_id() === get_current_user_id())) {
wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) );
}
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode( 'woothankyouform', 'xnagyg_woocommerce_thankyou' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment