4

I want to get customer balance(store credit) by customer id in custom collection.

I am loading credit memo collection, so i want to show remaining customer balance with that.

3
  • You need it in phtml or root script?? Commented Jan 23, 2020 at 11:38
  • I am trying with root script, after that i will convert as phtml. Commented Jan 23, 2020 at 11:39
  • okay............ Commented Jan 23, 2020 at 11:39

1 Answer 1

6

Below is the code which useful to get store credit..

<?php
use \Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap     = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$instance      = \Magento\Framework\App\ObjectManager::getInstance();
$state         = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');

$balanceCollection = $objectManager->get('Magento\CustomerBalance\Model\BalanceFactory');
$model = $balanceCollection->create();
$model->setCustomerId(1)->loadByCustomer(); // put your customer id here
echo $model->getAmount();
?>
3
  • let me try and check it... Commented Jan 23, 2020 at 11:42
  • Sure........... Commented Jan 23, 2020 at 11:47
  • Thanks, it's working fine for me. Commented Jan 23, 2020 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.