diff --git a/assets/js/frontend/checkout.js b/assets/js/frontend/checkout.js index c0c52373ced..bd9fb9fbe60 100644 --- a/assets/js/frontend/checkout.js +++ b/assets/js/frontend/checkout.js @@ -163,6 +163,11 @@ jQuery(document).ready(function($) { } else { $('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 diff --git a/assets/js/frontend/checkout.min.js b/assets/js/frontend/checkout.min.js index 2755edb05c9..279a687003b 100644 --- a/assets/js/frontend/checkout.min.js +++ b/assets/js/frontend/checkout.min.js @@ -1 +1 @@ -jQuery(document).ready(function(e){function i(){r&&r.abort();var t=[];e("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(n,r){t[e(this).data("index")]=e(this).val()});var n=e("#order_review input[name=payment_method]:checked").val(),i=e("#billing_country").val(),s=e("#billing_state").val(),o=e("input#billing_postcode").val(),u=e("input#billing_city").val(),a=e("input#billing_address_1").val(),f=e("input#billing_address_2").val();if(e("#ship-to-different-address input").is(":checked")||e("#ship-to-different-address input").size()==0)var l=e("#shipping_country").val(),c=e("#shipping_state").val(),h=e("input#shipping_postcode").val(),p=e("input#shipping_city").val(),d=e("input#shipping_address_1").val(),v=e("input#shipping_address_2").val();else var l=i,c=s,h=o,p=u,d=a,v=f;e("#order_methods, #order_review").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var m={action:"woocommerce_update_order_review",security:wc_checkout_params.update_order_review_nonce,shipping_method:t,payment_method:n,country:i,state:s,postcode:o,city:u,address:a,address_2:f,s_country:l,s_state:c,s_postcode:h,s_city:p,s_address:d,s_address_2:v,post_data:e("form.checkout").serialize()};r=e.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:m,success:function(t){if(t){var n=e(t);e("#order_review").html(n.html());e("body").trigger("updated_checkout")}}})}function s(){var t=!0;if(e(n).size()){$required_siblings=e(n).closest(".form-row").siblings(".address-field.validate-required");$required_siblings.size()&&$required_siblings.each(function(){if(e(this).find("input.input-text").val()==""||e(this).find("input.input-text").val()=="undefined")t=!1})}if(t){n=!1;e("body").trigger("update_checkout")}}if(typeof wc_checkout_params=="undefined")return!1;var t,n=!1,r;e("body").bind("update_checkout",function(){clearTimeout(t);i()});e("p.password, form.login, .checkout_coupon, div.shipping_address").hide();e("input.show_password").change(function(){e("p.password").slideToggle()});e("a.showlogin").click(function(){e("form.login").slideToggle();return!1});e("a.showcoupon").click(function(){e(".checkout_coupon").slideToggle(400,function(){e("#coupon_code").focus()});return!1});e("#ship-to-different-address input").change(function(){e("div.shipping_address").hide();e(this).is(":checked")&&e("div.shipping_address").slideDown()}).change();if(wc_checkout_params.option_guest_checkout=="yes"){e("div.create-account").hide();e("input#createaccount").change(function(){e("div.create-account").hide();e(this).is(":checked")&&e("div.create-account").slideDown()}).change()}e("#order_review").on("click",".payment_methods input.input-radio",function(){if(e(".payment_methods input.input-radio").length>1){var t=e("div.payment_box."+e(this).attr("ID"));if(e(this).is(":checked")&&!t.is(":visible")){e("div.payment_box").filter(":visible").slideUp(250);e(this).is(":checked")&&e("div.payment_box."+e(this).attr("ID")).slideDown(250)}}else e("div.payment_box").show()}).find("input[name=payment_method]:checked").click();e("form.checkout").on("input change","select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select",function(){clearTimeout(t);n=!1;e("body").trigger("update_checkout")}).on("input change",".address-field input.input-text, .update_totals_on_change input.input-text",function(){n&&s()}).on("input change",".address-field select",function(){n=this;s()}).on("keydown",".address-field input.input-text, .update_totals_on_change input.input-text",function(e){var r=e.keyCode||e.which;if(r=="9")return;n=this;clearTimeout(t);t=setTimeout(s,"1000")}).on("blur input change",".input-text, select",function(){var t=e(this),n=t.closest(".form-row"),r=!0;if(n.is(".validate-required")&&t.val()==""){n.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-required-field");r=!1}if(n.is(".validate-email")&&t.val()){var i=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);if(!i.test(t.val())){n.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-email");r=!1}}r&&n.removeClass("woocommerce-invalid woocommerce-invalid-required-field").addClass("woocommerce-validated")}).submit(function(){clearTimeout(t);var n=e(this);if(n.is(".processing"))return!1;if(n.triggerHandler("checkout_place_order")!==!1&&n.triggerHandler("checkout_place_order_"+e("#order_review input[name=payment_method]:checked").val())!==!1){n.addClass("processing");var r=n.data();r["blockUI.isBlocked"]!=1&&n.block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});e.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:n.serialize(),success:function(t){var r="";try{t.indexOf("")>=0&&(t=t.split("")[1]);t.indexOf("")>=0&&(t=t.split("")[0]);r=e.parseJSON(t);if(r.result!="success")throw r.result=="failure"?"Result failure":"Invalid response";window.location=decodeURI(r.redirect)}catch(i){if(r.reload=="true"){window.location.reload();return}e(".woocommerce-error, .woocommerce-message").remove();r.messages?n.prepend(r.messages):n.prepend(t);n.removeClass("processing").unblock();n.find(".input-text, select").blur();e("html, body").animate({scrollTop:e("form.checkout").offset().top-100},1e3);r.refresh=="true"&&e("body").trigger("update_checkout");e("body").trigger("checkout_error")}},dataType:"html"})}return!1});e("form.checkout_coupon").submit(function(){var t=e(this);if(t.is(".processing"))return!1;t.addClass("processing").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var n={action:"woocommerce_apply_coupon",security:wc_checkout_params.apply_coupon_nonce,coupon_code:t.find("input[name=coupon_code]").val()};e.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:n,success:function(n){e(".woocommerce-error, .woocommerce-message").remove();t.removeClass("processing").unblock();if(n){t.before(n);t.slideUp();e("body").trigger("update_checkout")}},dataType:"html"});return!1});e("body").bind("init_checkout",function(){e("#billing_country, #shipping_country, .country_to_state").change();e("body").trigger("update_checkout")});wc_checkout_params.is_checkout==1&&e("body").trigger("init_checkout")}); \ No newline at end of file +jQuery(document).ready(function(e){function i(){r&&r.abort();var t=[];e("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(n,r){t[e(this).data("index")]=e(this).val()});var n=e("#order_review input[name=payment_method]:checked").val(),i=e("#billing_country").val(),s=e("#billing_state").val(),o=e("input#billing_postcode").val(),u=e("input#billing_city").val(),a=e("input#billing_address_1").val(),f=e("input#billing_address_2").val();if(e("#ship-to-different-address input").is(":checked")||e("#ship-to-different-address input").size()==0)var l=e("#shipping_country").val(),c=e("#shipping_state").val(),h=e("input#shipping_postcode").val(),p=e("input#shipping_city").val(),d=e("input#shipping_address_1").val(),v=e("input#shipping_address_2").val();else var l=i,c=s,h=o,p=u,d=a,v=f;e("#order_methods, #order_review").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var m={action:"woocommerce_update_order_review",security:wc_checkout_params.update_order_review_nonce,shipping_method:t,payment_method:n,country:i,state:s,postcode:o,city:u,address:a,address_2:f,s_country:l,s_state:c,s_postcode:h,s_city:p,s_address:d,s_address_2:v,post_data:e("form.checkout").serialize()};r=e.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:m,success:function(t){if(t){var n=e(t);e("#order_review").html(n.html());e("body").trigger("updated_checkout")}}})}function s(){var t=!0;if(e(n).size()){$required_siblings=e(n).closest(".form-row").siblings(".address-field.validate-required");$required_siblings.size()&&$required_siblings.each(function(){if(e(this).find("input.input-text").val()==""||e(this).find("input.input-text").val()=="undefined")t=!1})}if(t){n=!1;e("body").trigger("update_checkout")}}if(typeof wc_checkout_params=="undefined")return!1;var t,n=!1,r;e("body").bind("update_checkout",function(){clearTimeout(t);i()});e("p.password, form.login, .checkout_coupon, div.shipping_address").hide();e("input.show_password").change(function(){e("p.password").slideToggle()});e("a.showlogin").click(function(){e("form.login").slideToggle();return!1});e("a.showcoupon").click(function(){e(".checkout_coupon").slideToggle(400,function(){e("#coupon_code").focus()});return!1});e("#ship-to-different-address input").change(function(){e("div.shipping_address").hide();e(this).is(":checked")&&e("div.shipping_address").slideDown()}).change();if(wc_checkout_params.option_guest_checkout=="yes"){e("div.create-account").hide();e("input#createaccount").change(function(){e("div.create-account").hide();e(this).is(":checked")&&e("div.create-account").slideDown()}).change()}e("#order_review").on("click",".payment_methods input.input-radio",function(){if(e(".payment_methods input.input-radio").length>1){var t=e("div.payment_box."+e(this).attr("ID"));if(e(this).is(":checked")&&!t.is(":visible")){e("div.payment_box").filter(":visible").slideUp(250);e(this).is(":checked")&&e("div.payment_box."+e(this).attr("ID")).slideDown(250)}}else e("div.payment_box").show();e(this).data("order_button_text")?e("#place_order").val(e(this).data("order_button_text")):e("#place_order").val(e("#place_order").data("value"))}).find("input[name=payment_method]:checked").click();e("form.checkout").on("input change","select.shipping_method, input[name^=shipping_method], #ship-to-different-address input, .update_totals_on_change select",function(){clearTimeout(t);n=!1;e("body").trigger("update_checkout")}).on("input change",".address-field input.input-text, .update_totals_on_change input.input-text",function(){n&&s()}).on("input change",".address-field select",function(){n=this;s()}).on("keydown",".address-field input.input-text, .update_totals_on_change input.input-text",function(e){var r=e.keyCode||e.which;if(r=="9")return;n=this;clearTimeout(t);t=setTimeout(s,"1000")}).on("blur input change",".input-text, select",function(){var t=e(this),n=t.closest(".form-row"),r=!0;if(n.is(".validate-required")&&t.val()==""){n.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-required-field");r=!1}if(n.is(".validate-email")&&t.val()){var i=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);if(!i.test(t.val())){n.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-email");r=!1}}r&&n.removeClass("woocommerce-invalid woocommerce-invalid-required-field").addClass("woocommerce-validated")}).submit(function(){clearTimeout(t);var n=e(this);if(n.is(".processing"))return!1;if(n.triggerHandler("checkout_place_order")!==!1&&n.triggerHandler("checkout_place_order_"+e("#order_review input[name=payment_method]:checked").val())!==!1){n.addClass("processing");var r=n.data();r["blockUI.isBlocked"]!=1&&n.block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});e.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:n.serialize(),success:function(t){var r="";try{t.indexOf("")>=0&&(t=t.split("")[1]);t.indexOf("")>=0&&(t=t.split("")[0]);r=e.parseJSON(t);if(r.result!="success")throw r.result=="failure"?"Result failure":"Invalid response";window.location=decodeURI(r.redirect)}catch(i){if(r.reload=="true"){window.location.reload();return}e(".woocommerce-error, .woocommerce-message").remove();r.messages?n.prepend(r.messages):n.prepend(t);n.removeClass("processing").unblock();n.find(".input-text, select").blur();e("html, body").animate({scrollTop:e("form.checkout").offset().top-100},1e3);r.refresh=="true"&&e("body").trigger("update_checkout");e("body").trigger("checkout_error")}},dataType:"html"})}return!1});e("form.checkout_coupon").submit(function(){var t=e(this);if(t.is(".processing"))return!1;t.addClass("processing").block({message:null,overlayCSS:{background:"#fff url("+wc_checkout_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});var n={action:"woocommerce_apply_coupon",security:wc_checkout_params.apply_coupon_nonce,coupon_code:t.find("input[name=coupon_code]").val()};e.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:n,success:function(n){e(".woocommerce-error, .woocommerce-message").remove();t.removeClass("processing").unblock();if(n){t.before(n);t.slideUp();e("body").trigger("update_checkout")}},dataType:"html"});return!1});e("body").bind("init_checkout",function(){e("#billing_country, #shipping_country, .country_to_state").change();e("body").trigger("update_checkout")});wc_checkout_params.is_checkout==1&&e("body").trigger("init_checkout")}); \ No newline at end of file diff --git a/includes/abstracts/abstract-wc-payment-gateway.php b/includes/abstracts/abstract-wc-payment-gateway.php index 8b8a6e665a2..cc94893b219 100644 --- a/includes/abstracts/abstract-wc-payment-gateway.php +++ b/includes/abstracts/abstract-wc-payment-gateway.php @@ -19,6 +19,9 @@ abstract class WC_Payment_Gateway extends WC_Settings_API { /** @var string Payment method 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 $title; diff --git a/includes/gateways/paypal/class-wc-gateway-paypal.php b/includes/gateways/paypal/class-wc-gateway-paypal.php index f98609d8abe..358de885953 100644 --- a/includes/gateways/paypal/class-wc-gateway-paypal.php +++ b/includes/gateways/paypal/class-wc-gateway-paypal.php @@ -25,13 +25,14 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway { */ public function __construct() { - $this->id = 'paypal'; - $this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' ); - $this->has_fields = false; - $this->liveurl = 'https://www.paypal.com/cgi-bin/webscr'; - $this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; - $this->method_title = __( 'PayPal', 'woocommerce' ); - $this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Paypal', home_url( '/' ) ) ); + $this->id = 'paypal'; + $this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' ); + $this->has_fields = false; + $this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' ); + $this->liveurl = 'https://www.paypal.com/cgi-bin/webscr'; + $this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; + $this->method_title = __( 'PayPal', 'woocommerce' ); + $this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'WC_Gateway_Paypal', home_url( '/' ) ) ); // Load the settings. $this->init_form_fields(); diff --git a/readme.txt b/readme.txt index 82b86be6e23..16d16f05b6e 100644 --- a/readme.txt +++ b/readme.txt @@ -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 - Compatible with WordPress 3.8 default theme 'TwentyFourteen'. * 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 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. diff --git a/templates/checkout/form-pay.php b/templates/checkout/form-pay.php index 9e66ae13c82..4ea5bb95204 100644 --- a/templates/checkout/form-pay.php +++ b/templates/checkout/form-pay.php @@ -62,7 +62,7 @@ global $woocommerce; foreach ( $available_gateways as $gateway ) { ?>
  • - chosen ) echo 'checked="checked"'; ?> /> + chosen, true ); ?> data-order_button_text="order_button_text ); ?>" /> has_fields() || $gateway->get_description() ) { @@ -87,7 +87,8 @@ global $woocommerce; ' ); + + echo apply_filters( 'woocommerce_pay_order_button_html', '' ); ?> diff --git a/templates/checkout/review-order.php b/templates/checkout/review-order.php index 0727a681876..4dbea632d77 100644 --- a/templates/checkout/review-order.php +++ b/templates/checkout/review-order.php @@ -132,7 +132,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly foreach ( $available_gateways as $gateway ) { ?>
  • - chosen, true ); ?> /> + chosen, true ); ?> data-order_button_text="order_button_text ); ?>" /> has_fields() || $gateway->get_description() ) : @@ -167,7 +167,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ' ); + echo apply_filters( 'woocommerce_order_button_html', '' ); ?> 0 && apply_filters( 'woocommerce_checkout_show_terms', true ) ) { diff --git a/templates/myaccount/form-add-payment-method.php b/templates/myaccount/form-add-payment-method.php index 1b83297bf2c..0b79b352d4c 100644 --- a/templates/myaccount/form-add-payment-method.php +++ b/templates/myaccount/form-add-payment-method.php @@ -23,7 +23,7 @@ global $woocommerce; foreach ( $available_gateways as $gateway ) { ?>
  • - chosen) echo 'checked="checked"'; ?> /> + chosen, true ); ?> /> has_fields() || $gateway->get_description() ) {