BACS, Cheque, COD Closes #3172

Rather than merging them (they are all different) I've refactered code
and added multiple accounts in BACS which has had multiple requests.
This commit is contained in:
Mike Jolley 2013-08-05 16:34:48 +01:00
parent 7ad7f31e3b
commit 110d8c3026
9 changed files with 322 additions and 336 deletions

File diff suppressed because one or more lines are too long

View File

@ -1569,7 +1569,7 @@ a.export_rates, a.import_rates {
margin-top: -2px;
margin-bottom: 0;
}
table.wc_tax_rates {
table.wc_tax_rates, table.wc_input_table {
td {
padding: 0;
border-right: 1px solid #DFDFDF;
@ -1611,7 +1611,7 @@ table.wc_tax_rates {
padding: 0;
}
td.sort {
padding-left: 2em;
padding: 0 0 0 2em;
cursor: move;
position: relative;
background: #f9f9f9;

View File

@ -11,6 +11,85 @@ jQuery(function(){
'delay' : 200
});
// wc_input_table tables
jQuery('.wc_input_table.sortable tbody').sortable({
items:'tr',
cursor:'move',
axis:'y',
scrollSensitivity:40,
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){
ui.item.css('background-color','#f6f6f6');
},
stop:function(event,ui){
ui.item.removeAttr('style');
}
});
jQuery('.wc_input_table .remove_rows').click(function() {
var $tbody = jQuery(this).closest('.wc_input_table').find('tbody');
if ( $tbody.find('tr.current').size() > 0 ) {
$current = $tbody.find('tr.current');
$current.each(function(){
jQuery(this).remove();
});
}
return false;
});
var controlled = false;
var shifted = false;
var hasFocus = false;
jQuery(document).bind('keyup keydown', function(e){ shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey } );
jQuery('.wc_input_table').on( 'focus click', 'input', function( e ) {
$this_table = jQuery(this).closest('table');
$this_row = jQuery(this).closest('tr');
if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && jQuery(this).is(':focus') ) ) {
hasFocus = $this_row.index();
if ( ! shifted && ! controlled ) {
jQuery('tr', $this_table).removeClass('current').removeClass('last_selected');
$this_row.addClass('current').addClass('last_selected');
} else if ( shifted ) {
jQuery('tr', $this_table).removeClass('current');
$this_row.addClass('selected_now').addClass('current');
if ( jQuery('tr.last_selected', $this_table).size() > 0 ) {
if ( $this_row.index() > jQuery('tr.last_selected, $this_table').index() ) {
jQuery('tr', $this_table).slice( jQuery('tr.last_selected', $this_table).index(), $this_row.index() ).addClass('current');
} else {
jQuery('tr', $this_table).slice( $this_row.index(), jQuery('tr.last_selected', $this_table).index() + 1 ).addClass('current');
}
}
jQuery('tr', $this_table).removeClass('last_selected');
$this_row.addClass('last_selected');
} else {
jQuery('tr', $this_table).removeClass('last_selected');
if ( controlled && jQuery(this).closest('tr').is('.current') ) {
$this_row.removeClass('current');
} else {
$this_row.addClass('current').addClass('last_selected');
}
}
jQuery('tr', $this_table).removeClass('selected_now');
}
}).on( 'blur', 'input', function( e ) {
hasFocus = false;
});
// Availability inputs
jQuery('select.availability').change(function(){
if (jQuery(this).val()=="specific") {
jQuery(this).closest('tr').next('tr').show();

View File

@ -1,3 +1,3 @@
/**
* WooCommerce Admin JS
*/jQuery(function(){jQuery(".tips, .help_tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200});jQuery("select.availability").change(function(){jQuery(this).val()=="specific"?jQuery(this).closest("tr").next("tr").show():jQuery(this).closest("tr").next("tr").hide()}).change();jQuery("body").on("click",".show_order_items",function(){jQuery(this).closest("td").find("table").toggle();return!1});jQuery(".hide_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()});jQuery(".show_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()});jQuery("input#woocommerce_demo_store").change(function(){jQuery(this).is(":checked")?jQuery("#woocommerce_demo_store_notice").closest("tr").show():jQuery("#woocommerce_demo_store_notice").closest("tr").hide()}).change()});
*/jQuery(function(){jQuery(".tips, .help_tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200});jQuery(".wc_input_table.sortable tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")}});jQuery(".wc_input_table .remove_rows").click(function(){var e=jQuery(this).closest(".wc_input_table").find("tbody");if(e.find("tr.current").size()>0){$current=e.find("tr.current");$current.each(function(){jQuery(this).remove()})}return!1});var e=!1,t=!1,n=!1;jQuery(document).bind("keyup keydown",function(n){t=n.shiftKey;e=n.ctrlKey||n.metaKey});jQuery(".wc_input_table").on("focus click","input",function(r){$this_table=jQuery(this).closest("table");$this_row=jQuery(this).closest("tr");if(r.type=="focus"&&n!=$this_row.index()||r.type=="click"&&jQuery(this).is(":focus")){n=$this_row.index();if(!t&&!e){jQuery("tr",$this_table).removeClass("current").removeClass("last_selected");$this_row.addClass("current").addClass("last_selected")}else if(t){jQuery("tr",$this_table).removeClass("current");$this_row.addClass("selected_now").addClass("current");jQuery("tr.last_selected",$this_table).size()>0&&($this_row.index()>jQuery("tr.last_selected, $this_table").index()?jQuery("tr",$this_table).slice(jQuery("tr.last_selected",$this_table).index(),$this_row.index()).addClass("current"):jQuery("tr",$this_table).slice($this_row.index(),jQuery("tr.last_selected",$this_table).index()+1).addClass("current"));jQuery("tr",$this_table).removeClass("last_selected");$this_row.addClass("last_selected")}else{jQuery("tr",$this_table).removeClass("last_selected");e&&jQuery(this).closest("tr").is(".current")?$this_row.removeClass("current"):$this_row.addClass("current").addClass("last_selected")}jQuery("tr",$this_table).removeClass("selected_now")}}).on("blur","input",function(e){n=!1});jQuery("select.availability").change(function(){jQuery(this).val()=="specific"?jQuery(this).closest("tr").next("tr").show():jQuery(this).closest("tr").next("tr").hide()}).change();jQuery("body").on("click",".show_order_items",function(){jQuery(this).closest("td").find("table").toggle();return!1});jQuery(".hide_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()});jQuery(".show_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()});jQuery("input#woocommerce_demo_store").change(function(){jQuery(this).is(":checked")?jQuery("#woocommerce_demo_store_notice").closest("tr").show():jQuery("#woocommerce_demo_store_notice").closest("tr").hide()}).change()});

View File

@ -207,7 +207,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
?>
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'woocommerce' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'woocommerce' ) ); ?></h3>
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'woocommerce' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
<table class="wc_tax_rates widefat">
<table class="wc_tax_rates wc_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
@ -236,7 +236,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
<tr>
<th colspan="10">
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'woocommerce' ); ?></a>
<a href="#" class="button minus remove"><?php _e( 'Remove selected row(s)', 'woocommerce' ); ?></a>
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'woocommerce' ); ?></a>
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'woocommerce' ); ?></a>
<a href="<?php echo admin_url( 'admin.php?import=woocommerce_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'woocommerce' ); ?></a>
@ -306,24 +306,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
</table>
<script type="text/javascript">
jQuery( function() {
jQuery('.wc_tax_rates tbody').sortable({
items:'tr',
cursor:'move',
axis:'y',
scrollSensitivity:40,
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start:function(event,ui){
ui.item.css('background-color','#f6f6f6');
},
stop:function(event,ui){
ui.item.removeAttr('style');
}
});
jQuery('.wc_tax_rates .remove').click(function() {
jQuery('.wc_tax_rates .remove_tax_rates').click(function() {
var $tbody = jQuery('.wc_tax_rates').find('tbody');
if ( $tbody.find('tr.current').size() > 0 ) {
$current = $tbody.find('tr.current');
@ -331,12 +314,10 @@ class WC_Settings_Tax extends WC_Settings_Page {
$current.find('input.remove_tax_rate').val('1');
$current.each(function(){
if ( jQuery(this).is('.new') )
jQuery(this).remove();
else
jQuery(this).hide();
});
} else {
alert('<?php echo esc_js( __( 'No row(s) selected', 'woocommerce' ) ); ?>');
@ -344,53 +325,6 @@ class WC_Settings_Tax extends WC_Settings_Page {
return false;
});
var controlled = false;
var shifted = false;
var hasFocus = false;
jQuery(document).bind('keyup keydown', function(e){ shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey } );
jQuery('#rates').on( 'focus click', 'input', function( e ) {
$this_row = jQuery(this).closest('tr');
if ( ( e.type == 'focus' && hasFocus != $this_row.index() ) || ( e.type == 'click' && jQuery(this).is(':focus') ) ) {
hasFocus = $this_row.index();
if ( ! shifted && ! controlled ) {
jQuery('#rates tr').removeClass('current').removeClass('last_selected');
$this_row.addClass('current').addClass('last_selected');
} else if ( shifted ) {
jQuery('#rates tr').removeClass('current');
$this_row.addClass('selected_now').addClass('current');
if ( jQuery('#rates tr.last_selected').size() > 0 ) {
if ( $this_row.index() > jQuery('#rates tr.last_selected').index() ) {
jQuery('#rates tr').slice( jQuery('#rates tr.last_selected').index(), $this_row.index() ).addClass('current');
} else {
jQuery('#rates tr').slice( $this_row.index(), jQuery('#rates tr.last_selected').index() + 1 ).addClass('current');
}
}
jQuery('#rates tr').removeClass('last_selected');
$this_row.addClass('last_selected');
} else {
jQuery('#rates tr').removeClass('last_selected');
if ( controlled && jQuery(this).closest('tr').is('.current') ) {
$this_row.removeClass('current');
} else {
$this_row.addClass('current').addClass('last_selected');
}
}
jQuery('#rates tr').removeClass('selected_now');
}
}).on( 'blur', 'input', function( e ) {
hasFocus = false;
});
jQuery('.wc_tax_rates .export').click(function() {
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'woocommerce' ); ?>,<?php _e( 'State Code', 'woocommerce' ); ?>,<?php _e( 'ZIP/Postcode', 'woocommerce' ); ?>,<?php _e( 'City', 'woocommerce' ); ?>,<?php _e( 'Rate %', 'woocommerce' ); ?>,<?php _e( 'Tax Name', 'woocommerce' ); ?>,<?php _e( 'Priority', 'woocommerce' ); ?>,<?php _e( 'Compound', 'woocommerce' ); ?>,<?php _e( 'Shipping', 'woocommerce' ); ?>,<?php _e( 'Tax Class', 'woocommerce' ); ?>\n";

View File

@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*
* @class WC_Gateway_BACS
* @extends WC_Payment_Gateway
* @version 2.0.0
* @version 2.1.0
* @package WooCommerce/Classes/Payment
* @author WooThemes
*/
@ -17,83 +17,63 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'bacs';
$this->icon = apply_filters('woocommerce_bacs_icon', '');
$this->has_fields = false;
$this->method_title = __( 'Bacs', 'woocommerce' );
$this->id = 'bacs';
$this->icon = apply_filters('woocommerce_bacs_icon', '');
$this->has_fields = false;
$this->method_title = __( 'BACS', 'woocommerce' );
$this->method_description = __( 'Allows payments by BACS, more commonly known as direct bank/wire transfer.', 'woocommerce' );
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions', $this->description );
// BACS account fields shown on the thanks page and in emails
$this->account_fields = array(
'account_name' => array(
'label' => __( 'Account Name', 'woocommerce' ),
'value' => $this->get_option( 'account_name' )
),
'account_number'=> array(
'label' => __( 'Account Number', 'woocommerce' ),
'value' => $this->get_option( 'account_number' )
),
'sort_code' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
'value' => $this->get_option( 'sort_code' )
),
'bank_name' => array(
'label' => __( 'Bank Name', 'woocommerce' ),
'value' => $this->get_option( 'bank_name' )
),
'iban' => array(
'label' => __( 'IBAN', 'woocommerce' ),
'value' => $this->get_option( 'iban' )
),
'bic' => array(
'label' => __( 'BIC', 'woocommerce' ),
'value' => $this->get_option( 'bic' )
$this->account_details = get_option( 'woocommerce_bacs_accounts',
array(
array(
'account_name' => $this->get_option( 'account_name' ),
'account_number' => $this->get_option( 'account_number' ),
'sort_code' => $this->get_option( 'sort_code' ),
'bank_name' => $this->get_option( 'bank_name' ),
'iban' => $this->get_option( 'iban' ),
'bic' => $this->get_option( 'bic' )
)
)
);
// Actions
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) );
add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) );
// Customer Emails
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 2 );
}
/**
* Initialise Gateway Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable Bank Transfer', 'woocommerce' ),
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable Bank Transfer', 'woocommerce' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
'default' => __( 'Direct Bank Transfer', 'woocommerce' ),
'desc_tip' => true,
'default' => __( 'Direct Bank Transfer', 'woocommerce' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'woocommerce' ),
@ -110,96 +90,127 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'desc_tip' => true,
),
'account_details' => array(
'title' => __( 'Account Details', 'woocommerce' ),
'type' => 'title',
'description' => __( 'Optionally enter your bank details below for customers to pay into.', 'woocommerce' ),
'default' => ''
),
'account_name' => array(
'title' => __( 'Account Name', 'woocommerce' ),
'type' => 'text',
'description' => '',
'default' => ''
),
'account_number' => array(
'title' => __( 'Account Number', 'woocommerce' ),
'type' => 'text',
'description' => '',
'default' => ''
),
'sort_code' => array(
'title' => __( 'Sort Code', 'woocommerce' ),
'type' => 'text',
'description' => '',
'default' => ''
),
'bank_name' => array(
'title' => __( 'Bank Name', 'woocommerce' ),
'type' => 'text',
'description' => '',
'default' => ''
),
'iban' => array(
'title' => __( 'IBAN', 'woocommerce' ),
'type' => 'text',
'default' => ''
),
'bic' => array(
'title' => __( 'BIC (formerly Swift)', 'woocommerce' ),
'type' => 'text',
'default' => ''
'type' => 'account_details'
),
);
}
/**
* generate_account_details_html function.
*/
public function generate_account_details_html() {
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Account Details', 'woocommerce' ); ?>:</th>
<td class="forminp" id="bacs_accounts">
<table class="widefat wc_input_table sortable" cellspacing="0">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th><?php _e( 'Account Name', 'woocommerce' ); ?></th>
<th><?php _e( 'Account Number', 'woocommerce' ); ?></th>
<th><?php _e( 'Bank Name', 'woocommerce' ); ?></th>
<th><?php _e( 'Sort Code', 'woocommerce' ); ?></th>
<th><?php _e( 'IBAN', 'woocommerce' ); ?></th>
<th><?php _e( 'BIC / Swift', 'woocommerce' ); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="7"><a href="#" class="add button"><?php _e( '+ Add Account', 'woocommerce' ); ?></a> <a href="#" class="remove_rows button"><?php _e( 'Remove selected account(s)', 'woocommerce' ); ?></a></th>
</tr>
</tfoot>
<tbody class="accounts">
<?php
$i = -1;
if ( $this->account_details ) {
foreach ( $this->account_details as $account ) {
$i++;
/**
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
*
* @access public
* @return void
*/
public function admin_options() {
?>
<h3><?php _e( 'BACS Payment', 'woocommerce' ); ?></h3>
<p><?php _e('Allows payments by BACS (Bank Account Clearing System), more commonly known as direct bank/wire transfer.', 'woocommerce' ); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table><!--/.form-table-->
<?php
echo '<tr class="account">
<td class="sort"></td>
<td><input type="text" value="' . esc_attr( $account['account_name'] ) . '" name="bacs_account_name[' . $i . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['account_number'] ) . '" name="bacs_account_number[' . $i . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['bank_name'] ) . '" name="bacs_bank_name[' . $i . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['sort_code'] ) . '" name="bacs_sort_code[' . $i . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['iban'] ) . '" name="bacs_iban[' . $i . ']" /></td>
<td><input type="text" value="' . esc_attr( $account['bic'] ) . '" name="bacs_bic[' . $i . ']" /></td>
</tr>';
}
}
?>
</tbody>
</table>
<script type="text/javascript">
jQuery(function() {
jQuery('#bacs_accounts').on( 'click', 'a.add', function(){
var size = jQuery('#bacs_accounts tbody .account').size();
jQuery('<tr class="account">\
<td class="sort"></td>\
<td><input type="text" name="bacs_account_name[' + size + ']" /></td>\
<td><input type="text" name="bacs_account_number[' + size + ']" /></td>\
<td><input type="text" name="bacs_bank_name[' + size + ']" /></td>\
<td><input type="text" name="bacs_sort_code[' + size + ']" /></td>\
<td><input type="text" name="bacs_iban[' + size + ']" /></td>\
<td><input type="text" name="bacs_bic[' + size + ']" /></td>\
</tr>').appendTo('#bacs_accounts table tbody');
return false;
});
});
</script>
</td>
</tr>
<?php
return ob_get_clean();
}
/**
* Save account details table
*/
public function save_account_details() {
$accounts = array();
if ( isset( $_POST['bacs_account_name'] ) ) {
$account_names = array_map( 'woocommerce_clean', $_POST['bacs_account_name'] );
$account_numbers = array_map( 'woocommerce_clean', $_POST['bacs_account_number'] );
$bank_names = array_map( 'woocommerce_clean', $_POST['bacs_bank_name'] );
$sort_codes = array_map( 'woocommerce_clean', $_POST['bacs_sort_code'] );
$ibans = array_map( 'woocommerce_clean', $_POST['bacs_iban'] );
$bics = array_map( 'woocommerce_clean', $_POST['bacs_bic'] );
foreach ( $account_names as $i => $name ) {
if ( ! isset( $account_names[ $i ] ) )
continue;
$accounts[] = array(
'account_name' => $account_names[ $i ],
'account_number' => $account_numbers[ $i ],
'bank_name' => $bank_names[ $i ],
'sort_code' => $sort_codes[ $i ],
'iban' => $ibans[ $i ],
'bic' => $bics[ $i ]
);
}
}
update_option( 'woocommerce_bacs_accounts', $accounts );
}
/**
* Output for the order received page.
*
* @access public
* @return void
*/
function thankyou_page( $order_id ) {
public function thankyou_page( $order_id ) {
if ( $this->instructions )
echo wpautop( wptexturize( wp_kses_post( $this->instructions ) ) );
echo '<h2>' . __( 'Our Details', 'woocommerce' ) . '</h2>';
echo '<ul class="order_details bacs_details">';
$fields = apply_filters( 'woocommerce_bacs_fields', $this->account_fields, $order_id );
foreach ( $fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) {
echo '<li class="' . esc_attr( $field_key ) . '">' . esc_attr( $field['label'] ) . ': <strong>' . wptexturize( $field['value'] ) . '</strong></li>';
}
}
echo '</ul>';
$this->bank_details( $order_id );
}
/**
* Add content to the WC emails.
*
@ -208,51 +219,86 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
* @param bool $sent_to_admin
* @return void
*/
function email_instructions( $order, $sent_to_admin ) {
public function email_instructions( $order, $sent_to_admin ) {
if ( $sent_to_admin ) return;
if ( $order->status !== 'on-hold') return;
if ( $order->payment_method !== 'bacs') return;
if ( $sent_to_admin || $order->status !== 'on-hold' || $order->payment_method !== 'bacs' )
return;
if ( $this->instructions )
echo wpautop( wptexturize( $this->instructions ) );
?><h2><?php _e( 'Our Details', 'woocommerce' ) ?></h2><ul class="order_details bacs_details"><?php
$fields = apply_filters( 'woocommerce_bacs_fields', $this->account_fields, $order->id );
foreach ( $fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) {
echo '<li class="' . esc_attr( $field_key ) . '">' . esc_attr( $field['label'] ) . ': <strong>' . wptexturize( $field['value'] ) . '</strong></li>';
}
}
?></ul><?php
$this->bank_details( $order->id );
}
/**
* Get bank details and place into a list format
*/
private function bank_details( $order_id = '' ) {
if ( empty( $this->account_details ) )
return;
echo '<h2>' . __( 'Our Bank Details', 'woocommerce' ) . '</h2>';
$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details );
if ( ! empty( $bacs_accounts ) ) {
foreach ( $bacs_accounts as $bacs_account ) {
echo '<ul class="order_details bacs_details">';
$bacs_account = (object) $bacs_account;
// BACS account fields shown on the thanks page and in emails
$account_fields = apply_filters( 'woocommerce_bacs_account_fields', array(
'account_number'=> array(
'label' => __( 'Account Number', 'woocommerce' ),
'value' => $bacs_account->account_number
),
'sort_code' => array(
'label' => __( 'Sort Code', 'woocommerce' ),
'value' => $bacs_account->sort_code
),
'iban' => array(
'label' => __( 'IBAN', 'woocommerce' ),
'value' => $bacs_account->iban
),
'bic' => array(
'label' => __( 'BIC', 'woocommerce' ),
'value' => $bacs_account->bic
)
), $order_id );
if ( $bacs_account->account_name || $bacs_account->bank_name )
echo '<h3>' . implode( ' - ', array_filter( array( $bacs_account->account_name, $bacs_account->bank_name ) ) ) . '</h3>';
foreach ( $account_fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) {
echo '<li class="' . esc_attr( $field_key ) . '">' . esc_attr( $field['label'] ) . ': <strong>' . wptexturize( $field['value'] ) . '</strong></li>';
}
}
echo '</ul>';
}
}
}
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
function process_payment( $order_id ) {
global $woocommerce;
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
// Mark as on-hold (we're awaiting the payment)
$order->update_status('on-hold', __( 'Awaiting BACS payment', 'woocommerce' ));
$order->update_status( 'on-hold', __( 'Awaiting BACS payment', 'woocommerce' ) );
// Reduce stock levels
$order->reduce_order_stock();
// Remove cart
$woocommerce->cart->empty_cart();
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
@ -260,5 +306,4 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
'redirect' => $this->get_return_url( $order )
);
}
}

View File

@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*
* @class WC_Gateway_Cheque
* @extends WC_Payment_Gateway
* @version 2.0.0
* @version 2.1.0
* @package WooCommerce/Classes/Payment
* @author WooThemes
*/
@ -17,15 +17,13 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'cheque';
$this->icon = apply_filters('woocommerce_cheque_icon', '');
$this->has_fields = false;
$this->method_title = __( 'Cheque', 'woocommerce' );
$this->id = 'cheque';
$this->icon = apply_filters('woocommerce_cheque_icon', '');
$this->has_fields = false;
$this->method_title = __( 'Cheque', 'woocommerce' );
$this->method_description = __( 'Allows cheque payments. Why would you take cheques in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce' );
// Load the settings.
$this->init_form_fields();
@ -44,14 +42,10 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 2 );
}
/**
* Initialise Gateway Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
@ -82,91 +76,54 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
'desc_tip' => true,
),
);
}
/**
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
*
* @access public
* @return void
*/
public function admin_options() {
?>
<h3><?php _e( 'Cheque Payment', 'woocommerce' ); ?></h3>
<p><?php _e( 'Allows cheque payments. Why would you take cheques in this day and age? Well you probably wouldn\'t but it does allow you to make test purchases for testing order emails and the \'success\' pages etc.', 'woocommerce' ); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table><!--/.form-table-->
<?php
}
/**
* Output for the order received page.
*
* @access public
* @return void
*/
function thankyou_page() {
public function thankyou_page() {
if ( $this->instructions )
echo wpautop( wptexturize( $this->instructions ) );
}
/**
* Add content to the WC emails.
*
* @access public
* @param WC_Order $order
* @param bool $sent_to_admin
* @return void
*/
function email_instructions( $order, $sent_to_admin ) {
if ( $sent_to_admin ) return;
if ( $order->status !== 'on-hold') return;
if ( $order->payment_method !== 'cheque') return;
public function email_instructions( $order, $sent_to_admin ) {
if ( $sent_to_admin || $order->status !== 'on-hold' || $order->payment_method !== 'cheque' )
return;
if ( $this->instructions )
echo wpautop( wptexturize( $this->instructions ) );
}
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
function process_payment( $order_id ) {
global $woocommerce;
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
// Mark as on-hold (we're awaiting the cheque)
$order->update_status('on-hold', __( 'Awaiting cheque payment', 'woocommerce' ));
$order->update_status( 'on-hold', __( 'Awaiting cheque payment', 'woocommerce' ) );
// Reduce stock levels
$order->reduce_order_stock();
// Remove cart
$woocommerce->cart->empty_cart();
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
}

View File

@ -9,23 +9,21 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
*
* @class WC_Gateway_COD
* @extends WC_Payment_Gateway
* @version 2.0.0
* @version 2.1.0
* @package WooCommerce/Classes/Payment
* @author Patrick Garman
* @author WooThemes
*/
class WC_Gateway_COD extends WC_Payment_Gateway {
/**
* Constructor for the gateway.
*
* @access public
* @return void
*/
function __construct() {
$this->id = 'cod';
$this->icon = apply_filters( 'woocommerce_cod_icon', '' );
$this->method_title = __( 'Cash on Delivery', 'woocommerce' );
$this->has_fields = false;
public function __construct() {
$this->id = 'cod';
$this->icon = apply_filters( 'woocommerce_cod_icon', '' );
$this->method_title = __( 'Cash on Delivery', 'woocommerce' );
$this->method_description = __( 'Have your customers pay with cash (or by other means) upon delivery.', 'woocommerce' );
$this->has_fields = false;
// Load the settings
$this->init_form_fields();
@ -41,31 +39,10 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
add_action( 'woocommerce_thankyou_cod', array( $this, 'thankyou' ) );
}
/**
* Admin Panel Options
* - Options for bits like 'title' and availability on a country-by-country basis
*
* @access public
* @return void
*/
function admin_options() {
?>
<h3><?php _e('Cash on Delivery','woocommerce'); ?></h3>
<p><?php _e('Have your customers pay with cash (or by other means) upon delivery.', 'woocommerce' ); ?></p>
<table class="form-table">
<?php $this->generate_settings_html(); ?>
</table> <?php
}
/**
* Initialise Gateway Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
public function init_form_fields() {
global $woocommerce;
$shipping_methods = array();
@ -77,30 +54,32 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable COD', 'woocommerce' ),
'label' => __( 'Enable Cash on Delivery', 'woocommerce' ),
'type' => 'checkbox',
'title' => __( 'Enable COD', 'woocommerce' ),
'label' => __( 'Enable Cash on Delivery', 'woocommerce' ),
'type' => 'checkbox',
'description' => '',
'default' => 'no'
'default' => 'no'
),
'title' => array(
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Payment method title that the customer will see on your website.', 'woocommerce' ),
'default' => __( 'Cash on Delivery', 'woocommerce' ),
'desc_tip' => true,
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
'default' => __( 'Cash on Delivery', 'woocommerce' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'woocommerce' ),
'type' => 'textarea',
'title' => __( 'Description', 'woocommerce' ),
'type' => 'textarea',
'description' => __( 'Payment method description that the customer will see on your website.', 'woocommerce' ),
'default' => __( 'Pay with cash upon delivery.', 'woocommerce' ),
'default' => __( 'Pay with cash upon delivery.', 'woocommerce' ),
'desc_tip' => true,
),
'instructions' => array(
'title' => __( 'Instructions', 'woocommerce' ),
'type' => 'textarea',
'title' => __( 'Instructions', 'woocommerce' ),
'type' => 'textarea',
'description' => __( 'Instructions that will be added to the thank you page.', 'woocommerce' ),
'default' => __( 'Pay with cash upon delivery.', 'woocommerce' )
'default' => __( 'Pay with cash upon delivery.', 'woocommerce' ),
'desc_tip' => true,
),
'enable_for_methods' => array(
'title' => __( 'Enable for shipping methods', 'woocommerce' ),
@ -115,14 +94,12 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
);
}
/**
* Check If The Gateway Is Available For Use
*
* @access public
* @return bool
*/
function is_available() {
public function is_available() {
global $woocommerce;
if ( ! empty( $this->enable_for_methods ) ) {
@ -159,16 +136,13 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
return parent::is_available();
}
/**
* Process the payment and return the result
*
* @access public
* @param int $order_id
* @return array
*/
function process_payment($order_id) {
global $woocommerce;
public function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
@ -179,7 +153,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$order->reduce_order_stock();
// Remove cart
$woocommerce->cart->empty_cart();
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
@ -188,15 +162,11 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
);
}
/**
* Output for the order received page.
*
* @access public
* @return void
*/
function thankyou() {
echo $this->instructions != '' ? wpautop( $this->instructions ) : '';
public function thankyou_page() {
if ( $this->instructions )
echo wpautop( wptexturize( $this->instructions ) );
}
}

View File

@ -176,6 +176,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Ability to link past orders to a customer (before they registered).
* Feature - Authorize option for paypal standard.
* Feature - Separate options for countries you can ship to and sell to.
* Feature - BACS supports multiple account details.
* Tweak - Added filter to check the 'Create account' checkbox on checkout by default.
* Tweak - Update CPT parameters for 'product_variation' and 'shop_coupon' to be no longer public.
* Tweak - COD processing instead of on-hold.