3

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.

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

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();
?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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