Skip to content

Instantly share code, notes, and snippets.

@prasadnevase
Last active July 10, 2020 11:29
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasadnevase/a0fd6e23f8d846cebb82ab25726b88d8 to your computer and use it in GitHub Desktop.
Save prasadnevase/a0fd6e23f8d846cebb82ab25726b88d8 to your computer and use it in GitHub Desktop.
WooCommerce - Shortcode to list BACS accounts on checkout page
<?php
/* Usage: Put [bacs_account_details] shortcode in "WooCommerce > Settings > Checkout > BACS > Description field" */
/* This function outputs the BACS account details */
function list_bacs_accounts() {
$accounts = get_option( 'woocommerce_bacs_accounts');
if ( $accounts ) {
$list_accounts = '<table>
<thead>
<th>Account Name</th>
<th>Account Number</th>
<th>Bank Name</th>
<th>IFSC</th>
<th>IBAN</th>
<th>BIC / Swift</th>
</thead>';
for ( $i = 0; $i < sizeof($accounts); $i++ ) {
$list_accounts .= '
<tr class="account">
<td><p>' . wp_unslash( $accounts[$i]['account_name'] ) . '</p></td>
<td><p>' . $accounts[$i]['account_number'] . '</p></td>
<td><p>' . wp_unslash( $accounts[$i]['bank_name'] ) . '</p></td>
<td><p>' . $accounts[$i]['sort_code'] . '</p></td>
<td><p>' . $accounts[$i]['iban'] . '</p></td>
<td><p>' . $accounts[$i]['bic'] . '</p></td>
</tr>';
}
$list_accounts .= '</table>';
}
return $list_accounts;
}
add_shortcode( 'bacs_account_details', 'list_bacs_accounts' );
/* This function simply passess description field to the_content filter so that our shortcode is handled.
By default it does not handle any shortcodes. */
function gateway_desc_schortcode_handler( $description , $id ) {
global $woocommerce;
return apply_filters( 'the_content', $description );
}
add_filter( 'woocommerce_gateway_description', 'gateway_desc_schortcode_handler');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment