Extend BC for WP: Show customers their available store credit

The Bigcommerce for Wordpress plugin adds flexibility to the BC platform, but needs some upgrades here and there. In this post I'll show you how to add a summary for the customers available store credit.

Bigcommerce is a small, but growing platform; they were wise to tap into the WordPress community as a headless implementation. It has provided my team the power to create responsive WordPress pages using Elementor without giving up the robust scalability of a dedicated e-com backend.

Now I will admit, the BC plugin is not perfect. It has a few shortcomings and I’m going to show you a work-around for one of them below. The customers’ available store credit does not show up anywhere within the WordPress UI. The following code will remedy that.

Place this code into your WordPress theme’s function file or a relevant class file:

public function add_profile_fields( $fields ){
   
   $fields['store_credit'] = 0.00;
   
   return $fields;
}

public function render_store_credit_notice( $content ) {
   
   $slugs_enabled = ['orders', 'my-account'];
   
   if ( is_page( $slugs_enabled ) ) {
      
      $customer = new Customer( get_current_user_id() );
      $store_credit = $customer->get_profile()['store_credit'];
      
      if ( $store_credit > 0 ) {
         
         $store_credit = round( $store_credit, 2 );
         
         $notice = '<div class="bc-alert" style="background-color: #e98802">
                   <span>You have </span>
                   <b>$' . sprintf("%1.2f", $store_credit ) . '</b> of store credit.
                   <span>To use it, simply place your order and you will be able to choose
                   store credit as the payment method during checkout.</span>
                   </div>';
         
         $content = $notice . $content;
      }
   }
   
   return $content;
}

Place these two lines at the bottom of your functions file or in the constructor of your relevant class file:

// Add store credit notice to account pages
add_filter( 'bigcommerce/customer/empty_profile', 'add_profile_fields' );
add_filter( 'the_content', 'render_store_credit_notice' );

The end result looks something like this from your WP account dashboard, assuming you have store credit available: