#StackBounty: #magento2 #checkout #event-observer #customer-attribute #order-success-page Get a Custom Customer Attribute to Appear on …

Bounty: 100

I’ve recently created a customer attribute for my Magento ver. 2.3.5-p1 instance using the following blog:

https://www.blog.sashas.org/magento-2-1-3-how-to-make-customer-attribute-update.html

The module has worked properly and created a new customer attribute with the i.d. "trade_ordernumber".

I would now like to add this attribute to the checkout success page but I’m not sure how to do this, what I was thinking was something like the below:

    <?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

?>
<?php /** @var $block MagentoCheckoutBlockOnepageSuccess */ ?>
<div class="checkout-success">
    <?php if ($block->getOrderId()) :?>
        <?php if ($block->getCanViewOrder()) :?>
                <h1><?= $block->escapeHtml(__('Your order # is: <span>%1</span>.', $block->getOrderId()), ['span']) ?></h1>
    
            <p><?= $block->escapeHtml(__('Your order number is: %1.', sprintf('<a href="%s" class="order-number"><strong>%s</strong></a>', $block->escapeUrl($block->getViewOrderUrl()), $block->getOrderId())), ['a', 'strong']) ?></p>
        <?php  else :?>
            <p><?= $block->escapeHtml(__('Your order # is: <span>%1</span>.', $block->getOrderId()), ['span']) ?></p>
        <?php endif;?>
            <p><?= $block->escapeHtml(__('We'll email you an order confirmation with details and tracking info.')) ?></p>
    <?php endif;?>

    <?= $block->getAdditionalInfoHtml() ?>

    <div class="actions-toolbar">
        <div class="primary">
            <a class="action primary continue" href="<?= $block->escapeUrl($block->getContinueUrl()) ?>"><span><?= $block->escapeHtml(__('Continue Shopping')) ?></span></a>
        </div>
    </div>
</div>


<?php
    $objectManager =  MagentoFrameworkAppObjectManager::getInstance();        
    $storeManager  = $objectManager->get('MagentoStoreModelStoreManagerInterface');
    $storeID       = $storeManager->getStore()->getStoreId(); 
    $storeName     = $storeManager->getStore()->getName();
?>

<?php
    $customerSession = $objectManager->get('MagentoCustomerModelSession');
    if($customerSession->isLoggedIn()) {
        echo $customerSession->getAttribute('trade_ordernumber');
    }
?>


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.