Added account endpoint for customer payment methods

This commit is contained in:
Claudio Sanches 2016-01-20 18:13:17 -02:00
parent d34c580e1d
commit 2de00c61ff
8 changed files with 188 additions and 55 deletions

View File

@ -102,6 +102,15 @@ class WC_Settings_Accounts extends WC_Settings_Page {
'desc_tip' => true,
),
array(
'title' => __( 'Payment Methods', 'woocommerce' ),
'desc' => __( 'Endpoint for the My Account → Payment Methods page', 'woocommerce' ),
'id' => 'woocommerce_myaccount_payment_methods_endpoint',
'type' => 'text',
'default' => 'payment-methods',
'desc_tip' => true,
),
array(
'title' => __( 'Lost Password', 'woocommerce' ),
'desc' => __( 'Endpoint for the My Account → Lost Password page', 'woocommerce' ),

View File

@ -72,6 +72,7 @@ class WC_Query {
'downloads' => get_option( 'woocommerce_myaccount_downloads_endpoint', 'downloads' ),
'edit-account' => get_option( 'woocommerce_myaccount_edit_account_endpoint', 'edit-account' ),
'edit-address' => get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ),
'payment-methods' => get_option( 'woocommerce_myaccount_payment_methods_endpoint', 'payment-methods' ),
'lost-password' => get_option( 'woocommerce_myaccount_lost_password_endpoint', 'lost-password' ),
'customer-logout' => get_option( 'woocommerce_logout_endpoint', 'customer-logout' ),
'add-payment-method' => get_option( 'woocommerce_myaccount_add_payment_method_endpoint', 'add-payment-method' ),
@ -113,6 +114,9 @@ class WC_Query {
case 'edit-address' :
$title = __( 'Edit Address', 'woocommerce' );
break;
case 'payment-methods' :
$title = __( 'Payment Methods', 'woocommerce' );
break;
case 'add-payment-method' :
$title = __( 'Add Payment Method', 'woocommerce' );
break;

View File

@ -81,6 +81,7 @@ function wc_get_account_menu_items() {
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => __( 'Addresses', 'woocommerce' ),
'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
'edit-account' => __( 'Account Details', 'woocommerce' ),
'customer-logout' => __( 'Logout', 'woocommerce' ),
) );
@ -193,3 +194,17 @@ function wc_get_account_downloads_columns() {
'download-actions' => ' ',
) );
}
/**
* Get My Account > Payment methods columns.
*
* @since 2.6.0
* @return array
*/
function wc_get_account_payment_methods_columns() {
return apply_filters( 'woocommerce_account_orders_columns', array(
'method' => __( 'Method', 'woocommerce' ),
'expires' => __( 'Expires', 'woocommerce' ),
'actions' => ' ',
) );
}

View File

@ -2061,16 +2061,6 @@ if ( ! function_exists( 'woocommerce_account_downloads' ) ) {
}
}
if ( ! function_exists( 'woocommerce_account_edit_account' ) ) {
/**
* My Account > Edit account template.
*/
function woocommerce_account_edit_account() {
WC_Shortcode_My_Account::edit_account();
}
}
if ( ! function_exists( 'woocommerce_account_edit_address' ) ) {
/**
@ -2085,6 +2075,15 @@ if ( ! function_exists( 'woocommerce_account_edit_address' ) ) {
}
}
if ( ! function_exists( 'woocommerce_account_payment_methods' ) ) {
/**
* My Account > Downloads template.
*/
function woocommerce_account_payment_methods() {
wc_get_template( 'myaccount/payment-methods.php' );
}
}
if ( ! function_exists( 'woocommerce_account_add_payment_method' ) ) {
@ -2095,3 +2094,13 @@ if ( ! function_exists( 'woocommerce_account_add_payment_method' ) ) {
WC_Shortcode_My_Account::add_payment_method();
}
}
if ( ! function_exists( 'woocommerce_account_edit_account' ) ) {
/**
* My Account > Edit account template.
*/
function woocommerce_account_edit_account() {
WC_Shortcode_My_Account::edit_account();
}
}

View File

@ -246,6 +246,7 @@ add_filter( 'jetpack_comment_form_enabled_for_product', '__return_false' );
add_action( 'woocommerce_account_orders_endpoint', 'woocommerce_account_orders' );
add_action( 'woocommerce_account_view-order_endpoint', 'woocommerce_account_view_order' );
add_action( 'woocommerce_account_downloads_endpoint', 'woocommerce_account_downloads' );
add_action( 'woocommerce_account_edit-account_endpoint', 'woocommerce_account_edit_account' );
add_action( 'woocommerce_account_edit-address_endpoint', 'woocommerce_account_edit_address' );
add_action( 'woocommerce_account_payment-methods_endpoint', 'woocommerce_account_payment_methods' );
add_action( 'woocommerce_account_add-payment-method_endpoint', 'woocommerce_account_add_payment_method' );
add_action( 'woocommerce_account_edit-account_endpoint', 'woocommerce_account_edit_account' );

View File

@ -585,9 +585,9 @@ add_action( 'template_redirect', 'wc_disable_author_archives_for_customers' );
/**
* Hooks into the `profile_update` hook to set the user last updated timestamp.
*
* @since 2.6
* @param int $user_id The user that was updated
* @param array $old The profile fields pre-change
* @since 2.6.0
* @param int $user_id The user that was updated.
* @param array $old The profile fields pre-change.
*/
function wc_update_profile_last_update_time( $user_id, $old ) {
wc_set_user_last_update_time( $user_id );
@ -598,11 +598,11 @@ add_action( 'profile_update', 'wc_update_profile_last_update_time', 10, 2 );
/**
* Hooks into the update user meta function to set the user last updated timestamp.
*
* @since 2.6
* @param int $meta_id ID of the meta object that was changed
* @param int $user_id The user that was updated
* @param string $meta_key Name of the meta key that was changed
* @param string $_meta_value Value of the meta that was changed
* @since 2.6.0
* @param int $meta_id ID of the meta object that was changed.
* @param int $user_id The user that was updated.
* @param string $meta_key Name of the meta key that was changed.
* @param string $_meta_value Value of the meta that was changed.
*/
function wc_meta_update_last_update_time( $meta_id, $user_id, $meta_key, $_meta_value ) {
$keys_to_track = apply_filters( 'woocommerce_user_last_update_fields', array( 'first_name', 'last_name' ) );
@ -627,9 +627,20 @@ add_action( 'update_user_meta', 'wc_meta_update_last_update_time', 10, 4 );
/**
* Sets a user's "last update" time to the current timestamp.
*
* @since 2.6
* @param int $user_id The user to set a timestamp for
* @since 2.6.0
* @param int $user_id The user to set a timestamp for.
*/
function wc_set_user_last_update_time( $user_id ) {
update_user_meta( $user_id, 'last_update', time() );
}
/**
* Get customer saved payment methods list.
*
* @since 2.6.0
* @param int $customer_id
* @return array
*/
function wc_get_customer_saved_methods_list( $customer_id ) {
return apply_filters( 'woocommerce_saved_payment_methods_list', array(), $customer_id );
}

View File

@ -13,46 +13,52 @@
* @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.1
* @version 2.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<form id="add_payment_method" method="post">
<div id="payment">
<?php if ( $available_gateways = WC()->payment_gateways->get_available_payment_gateways() ) : ?>
<ul class="payment_methods methods"><?php
// Chosen Method
if ( sizeof( $available_gateways ) ) {
current( $available_gateways )->set_current();
}
wc_get_template( 'myaccount/navigation.php' ); ?>
foreach ( $available_gateways as $gateway ) {
?>
<li class="payment_method_<?php echo $gateway->id; ?>">
<input id="payment_method_<?php echo $gateway->id; ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> />
<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<?php
if ( $gateway->has_fields() || $gateway->get_description() ) {
echo '<div class="payment_box payment_method_' . $gateway->id . '" style="display:none;">';
$gateway->payment_fields();
echo '</div>';
}
?>
</li>
<div class="my-account-content">
<?php if ( $available_gateways = WC()->payment_gateways->get_available_payment_gateways() ) : ?>
<form id="add_payment_method" method="post">
<div id="payment">
<ul class="payment_methods methods">
<?php
}
?></ul>
<div class="form-row">
<?php wp_nonce_field( 'woocommerce-add-payment-method' ); ?>
<input type="submit" class="button alt" id="place_order" value="<?php esc_attr_e( 'Add Payment Method', 'woocommerce' ); ?>" />
<input type="hidden" name="woocommerce_add_payment_method" value="1" />
// Chosen Method.
if ( count( $available_gateways ) ) {
current( $available_gateways )->set_current();
}
foreach ( $available_gateways as $gateway ) {
?>
<li class="payment_method_<?php echo $gateway->id; ?>">
<input id="payment_method_<?php echo $gateway->id; ?>" type="radio" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> />
<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<?php
if ( $gateway->has_fields() || $gateway->get_description() ) {
echo '<div class="payment_box payment_method_' . $gateway->id . '" style="display: none;">';
$gateway->payment_fields();
echo '</div>';
}
?>
</li>
<?php
}
?>
</ul>
<div class="form-row">
<?php wp_nonce_field( 'woocommerce-add-payment-method' ); ?>
<input type="submit" class="button alt" id="place_order" value="<?php esc_attr_e( 'Add Payment Method', 'woocommerce' ); ?>" />
<input type="hidden" name="woocommerce_add_payment_method" value="1" />
</div>
</div>
<?php else : ?>
<p><?php _e( 'Sorry, it seems that there are no payment methods which support adding a new payment method. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' ); ?></p>
<?php endif; ?>
</div>
</form>
</form>
<?php else : ?>
<p><?php esc_html_e( 'Sorry, it seems that there are no payment methods which support adding a new payment method. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' ); ?></p>
<?php endif; ?>
</div>

View File

@ -0,0 +1,78 @@
<?php
/**
* Payment methods
*
* Shows customer payment methods on the account page.
*
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/payment-methods.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* @see http://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$saved_methods = wc_get_customer_saved_methods_list( get_current_user_id() );
$has_methods = (bool) $saved_methods;
wc_print_notices(); ?>
<?php wc_get_template( 'myaccount/navigation.php' ); ?>
<div class="my-account-content">
<?php do_action( 'woocommerce_before_account_payment_methods', $has_methods ); ?>
<?php if ( $has_methods ) : ?>
<table class="shop_table shop_table_responsive account-payment-methods-table">
<thead>
<tr>
<?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
<th class="payment-method-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<?php foreach ( $saved_methods as $method ) : ?>
<tr class="method">
<?php foreach ( wc_get_account_payment_methods_columns() as $column_id => $column_name ) : ?>
<td class="payment-method-<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php
if ( has_action( 'woocommerce_account_payment_methods_column_' . $column_id ) ) {
do_action( 'woocommerce_account_payment_methods_column_' . $column_id, $method );
} else if ( 'method' === $column_id ) {
echo esc_html( $method['method'] );
} else if ( 'expires' === $column_id ) {
echo esc_html( $method['expires'] );
} else if ( 'actions' === $column_id ) {
foreach ( $method['actions'] as $key => $action ) {
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
}
}
?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
<?php else : ?>
<p><?php esc_html_e( 'No saved method found.', 'woocommerce' ); ?></p>
<?php endif; ?>
<?php do_action( 'woocommerce_after_account_payment_methods', $has_methods ); ?>
<a class="button" href="<?php echo esc_url( wc_get_endpoint_url( 'add-payment-method' ) ); ?>"><?php esc_html_e( 'Add New Payment Method', 'woocommerce' ); ?></a>
</div>