Guest Print Order on Checkout Success

Magento doesn’t allow guests to print their order on the checkout success page for security reasons but there’s a solution that doesn’t require any installation of extensions – simply modify one template.

OPTIONAL: Before we start, we’re going to be modifying the checkout success template which can be tricky because you’ve got to create a new order each time you view due to the session info being removed each time. To address this, I’d recommend you install a free clean extension that allows you to continually refresh the success page for any order you define (can be used for any future mods you might do) –  Yireo Checkout Tester (Hint: the order id you enter is just the order # without the store prefix, so order id “10001234” would be entered as ‘1234’)

OK, we’re ready to start –

Locate your success template (it’s probably at ‘app/design/frontend/default/YOURTHEME/template/checkout/success.phtml’ )

Make the change right before the ending endif in the “<?php if ($this->getCanViewOrder() && $this->getCanPrintOrder()) :?>” section and before the next endif


<?php if ($this->getCanViewOrder() && $this->getCanPrintOrder()) :?>
<p>
<?php echo $this->__('Click <a href="%s" onclick="this.target=\'_blank\'">here to print</a> a copy of your order confirmation.', $this->getPrintUrl()) ?>
<?php echo $this->getChildHtml() ?>
</p>

<!-- guest order view/print -->
<?php //endif;?>
<?php else : ?>
<?php $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId(); ?>
<?php $order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id); ?>
<?php $billing_address_data = $order_details->getbillingAddress(); ?>
<form id="guest_form" action="<?php echo Mage::getUrl('sales/guest/view/', array('_secure'=>true)) ?>" method="post" name="guest_form">
<input type="hidden" name="oar_order_id" value="<?php echo $order_id; ?>">
<input type="hidden" name="oar_billing_lastname" value="<?php echo $billing_address_data['lastname']; ?>">
<input type="hidden" name="oar_type" value="zip">
<input type="hidden" name="oar_email" value="">
<input type="hidden" name="oar_zip" value="<?php echo $billing_address_data['postcode']; ?>">
<p><?php echo $this->__('Click <a href="javascript:{}" onclick="document.getElementById(\'guest_form\').submit(); return false;">here to view or print</a> your order information'); ?></p>
</form>
<?php endif; ?>
<!-- end guest order view/print -->

<?php endif;?>

<?php if ($this->getAgreementRefId()): ?>

 

Test your changes and you’re done! .. What it’s doing is getting the guest’s order id and bringing them to the order info page as if they entered via ‘order lookup’ – It’s a “post” form, so no urls can be changed.

Here’s what the new page would look like (registered customers will continue to see the link as they always have – this only allows guests to view or print their order.

guest

Leave a Reply