From d3e122641d9c30ae35621877bf1d3b84fab37354 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 7 Dec 2011 17:36:58 +0000 Subject: [PATCH] add_inline_js helper for adding javascript to the footer --- classes/gateways/gateway-paypal.php | 46 ++++++++++++++--------------- classes/woocommerce.class.php | 30 +++++++++++++++++-- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/classes/gateways/gateway-paypal.php b/classes/gateways/gateway-paypal.php index 6da53589250..dcf083593fd 100644 --- a/classes/gateways/gateway-paypal.php +++ b/classes/gateways/gateway-paypal.php @@ -277,32 +277,30 @@ class woocommerce_paypal extends woocommerce_payment_gateway { $paypal_args_array[] = ''; } - return '
+ $woocommerce->add_inline_js(' + jQuery("body").block({ + message: "plugin_url() ).'/assets/images/ajax-loader.gif\" alt=\"Redirecting...\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to PayPal to make payment.', 'woothemes').'", + overlayCSS: + { + background: "#fff", + opacity: 0.6 + }, + css: { + padding: 20, + textAlign: "center", + color: "#555", + border: "3px solid #aaa", + backgroundColor:"#fff", + cursor: "wait", + lineHeight: "32px" + } + }); + jQuery("#submit_paypal_payment_form").click(); + '); + + return ' ' . implode('', $paypal_args_array) . ' '.__('Cancel order & restore cart', 'woothemes').' -
'; } diff --git a/classes/woocommerce.class.php b/classes/woocommerce.class.php index ecd660e7615..e6f27548623 100644 --- a/classes/woocommerce.class.php +++ b/classes/woocommerce.class.php @@ -15,6 +15,7 @@ class woocommerce { var $attribute_taxonomies; // Stores the attribute taxonomies used in the store var $plugin_url; var $plugin_path; + var $inline_js = ''; // Class instances var $query; @@ -40,9 +41,10 @@ class woocommerce { $this->load_messages(); // Hooks - add_filter('wp_redirect', array(&$this, 'redirect'), 1, 2); + add_filter( 'wp_redirect', array(&$this, 'redirect'), 1, 2 ); add_action( 'woocommerce_before_single_product', array(&$this, 'show_messages'), 10); add_action( 'woocommerce_before_shop_loop', array(&$this, 'show_messages'), 10); + add_action( 'wp_footer', array(&$this, 'output_inline_js'), 25); // Queue shipping and payment gateways add_action('plugins_loaded', array( &$this->shipping, 'init' ), 1); // Load shipping methods - some may be added by plugins @@ -351,5 +353,29 @@ class woocommerce { $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_woocommerce_product_total_stock_%')"); endif; } - + + /*-----------------------------------------------------------------------------------*/ + /* Inline JavaScript Helper (for adding it to the footer) */ + /*-----------------------------------------------------------------------------------*/ + + function add_inline_js( $code ) { + + $this->inline_js .= "\n" . $code . "\n"; + + } + + function output_inline_js() { + + if ($this->inline_js) : + + echo "\n\n"; + + endif; + + } + } \ No newline at end of file