Allow gateways to change the checkout place order button text on selection. Closes #4573

This commit is contained in:
Mike Jolley 2014-01-28 11:25:52 +00:00
parent bd76784f97
commit 39344f2ed5
8 changed files with 24 additions and 13 deletions

View File

@ -163,6 +163,11 @@ jQuery(document).ready(function($) {
} else { } else {
$('div.payment_box').show(); $('div.payment_box').show();
} }
if ( $(this).data('order_button_text') ) {
$('#place_order').val( $(this).data('order_button_text') );
} else {
$('#place_order').val( $('#place_order').data( 'value' ) );
}
}) })
// Trigger initial click // Trigger initial click

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,9 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
/** @var string Payment method ID. */ /** @var string Payment method ID. */
var $id; var $id;
/** @var string Set if the place order button should be renamed on selection. */
var $order_button_text;
/** @var string Payment method title. */ /** @var string Payment method title. */
var $title; var $title;

View File

@ -28,6 +28,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
$this->id = 'paypal'; $this->id = 'paypal';
$this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' ); $this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' );
$this->has_fields = false; $this->has_fields = false;
$this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' );
$this->liveurl = 'https://www.paypal.com/cgi-bin/webscr'; $this->liveurl = 'https://www.paypal.com/cgi-bin/webscr';
$this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; $this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$this->method_title = __( 'PayPal', 'woocommerce' ); $this->method_title = __( 'PayPal', 'woocommerce' );

View File

@ -189,6 +189,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - New notices API for adding errors/notices * Feature - New notices API for adding errors/notices
* Feature - Compatible with WordPress 3.8 default theme 'TwentyFourteen'. * Feature - Compatible with WordPress 3.8 default theme 'TwentyFourteen'.
* Feature - Added is_store_notice_showing conditional. * Feature - Added is_store_notice_showing conditional.
* Feature - Allow gateways to change the checkout place order button text on selection.
* Tweak - Added pagination to tax rate screens. * Tweak - Added pagination to tax rate screens.
* Tweak - Added filter to check the 'Create account' checkbox on checkout by default. * 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 - Update CPT parameters for 'product_variation' and 'shop_coupon' to be no longer public.

View File

@ -62,7 +62,7 @@ global $woocommerce;
foreach ( $available_gateways as $gateway ) { foreach ( $available_gateways as $gateway ) {
?> ?>
<li class="payment_method_<?php echo $gateway->id; ?>"> <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 if ( $gateway->chosen ) echo 'checked="checked"'; ?> /> <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 ); ?> data-order_button_text="<?php echo esc_attr( $gateway->order_button_text ); ?>" />
<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label> <label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<?php <?php
if ( $gateway->has_fields() || $gateway->get_description() ) { if ( $gateway->has_fields() || $gateway->get_description() ) {
@ -87,7 +87,8 @@ global $woocommerce;
<?php wp_nonce_field( 'woocommerce-pay' ); ?> <?php wp_nonce_field( 'woocommerce-pay' ); ?>
<?php <?php
$pay_order_button_text = apply_filters( 'woocommerce_pay_order_button_text', __( 'Pay for order', 'woocommerce' ) ); $pay_order_button_text = apply_filters( 'woocommerce_pay_order_button_text', __( 'Pay for order', 'woocommerce' ) );
echo apply_filters( 'woocommerce_pay_order_button_html', '<input type="submit" class="button alt" id="place_order" value="' . esc_attr( $pay_order_button_text ) . '" />' );
echo apply_filters( 'woocommerce_pay_order_button_html', '<input type="submit" class="button alt" id="place_order" value="' . esc_attr( $pay_order_button_text ) . '" data-value="' . esc_attr( $pay_order_button_text ) . '" />' );
?> ?>
<input type="hidden" name="woocommerce_pay" value="1" /> <input type="hidden" name="woocommerce_pay" value="1" />
</div> </div>

View File

@ -132,7 +132,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
foreach ( $available_gateways as $gateway ) { foreach ( $available_gateways as $gateway ) {
?> ?>
<li class="payment_method_<?php echo $gateway->id; ?>"> <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 ); ?> /> <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 ); ?> data-order_button_text="<?php echo esc_attr( $gateway->order_button_text ); ?>" />
<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label> <label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<?php <?php
if ( $gateway->has_fields() || $gateway->get_description() ) : if ( $gateway->has_fields() || $gateway->get_description() ) :
@ -167,7 +167,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<?php <?php
$order_button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) ); $order_button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
echo apply_filters( 'woocommerce_order_button_html', '<input type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" />' ); echo apply_filters( 'woocommerce_order_button_html', '<input type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '" />' );
?> ?>
<?php if ( wc_get_page_id( 'terms' ) > 0 && apply_filters( 'woocommerce_checkout_show_terms', true ) ) { <?php if ( wc_get_page_id( 'terms' ) > 0 && apply_filters( 'woocommerce_checkout_show_terms', true ) ) {

View File

@ -23,7 +23,7 @@ global $woocommerce;
foreach ( $available_gateways as $gateway ) { foreach ( $available_gateways as $gateway ) {
?> ?>
<li class="payment_method_<?php echo $gateway->id; ?>"> <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 if ($gateway->chosen) echo 'checked="checked"'; ?> /> <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> <label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<?php <?php
if ( $gateway->has_fields() || $gateway->get_description() ) { if ( $gateway->has_fields() || $gateway->get_description() ) {