From f8b15832d9096e743834e5a256f4f919e13ab943 Mon Sep 17 00:00:00 2001 From: Kcppdevelopers Date: Mon, 13 Mar 2017 18:11:04 +0530 Subject: [PATCH] Express Checkout - Ability to show/hide EC button in individual products, ref #425 --- ...eway-paypal-express-function-angelleye.php | 2 +- ...ateway-paypal-express-helper-angelleye.php | 22 ++++++---- paypal-for-woocommerce.php | 11 +++++ template/admin.php | 44 ++++++++++--------- 4 files changed, 50 insertions(+), 29 deletions(-) diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php index b8c59d08a..a92d27bce 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-function-angelleye.php @@ -203,7 +203,7 @@ public function ec_get_version() { } public function angelleye_ec_save_payment_method_checkbox() { - echo sprintf( + return sprintf( '

diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php index 982aa5176..717f09388 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php @@ -86,12 +86,16 @@ public function __construct() { public function buy_now_button() { try { global $post, $product; - $ec_html_button = ''; - if ($this->enabled == 'yes' && $this->show_on_product_page == 'yes') { + $_enable_ec_button = get_post_meta($product->id, '_enable_ec_button', true); + if($_enable_ec_button == 'no') { + return; + } + if ($this->enabled == 'yes' && ($this->show_on_product_page == 'yes' || $_enable_ec_button == 'yes')) { + $ec_html_button = ''; if ($this->enable_tokenized_payments == 'yes') { - $this->function_helper->angelleye_ec_save_payment_method_checkbox(); + $ec_html_button .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); } - $ec_html_button = '

'; + $ec_html_button .= '
'; $_product = wc_get_product($post->ID); $button_dynamic_class = 'single_variation_wrap_angelleye_' . $product->id; $hide = ''; @@ -372,13 +376,14 @@ public function woocommerce_paypal_express_checkout_button_angelleye($return = f return false; } if ($this->enabled == 'yes' && $this->show_on_cart == 'yes' && 0 < WC()->cart->total) { + $cart_button_html = ''; if ($this->enable_tokenized_payments == 'yes') { - $this->function_helper->angelleye_ec_save_payment_method_checkbox(); + $cart_button_html .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); } if($return == false) { do_action('angelleye_ec_before_buttom_cart_button', $this); } - $cart_button_html = ''; + $angelleyeOverlay = ''; switch ($this->checkout_with_pp_button_type) { case 'textbutton': @@ -422,13 +427,14 @@ public function checkout_message() { return false; } if (WC()->cart->total > 0) { + $ec_top_checkout_button = ''; wp_enqueue_script('angelleye_button'); echo '
'; if($this->enable_tokenized_payments == 'yes') { - $this->function_helper->angelleye_ec_save_payment_method_checkbox(); + $ec_top_checkout_button .= $this->function_helper->angelleye_ec_save_payment_method_checkbox(); } do_action('angelleye_ec_checkout_page_before_checkout_button', $this); - $ec_top_checkout_button = ''; + $ec_top_checkout_button .= '
'; $_angelleyeOverlay = ''; switch ($this->checkout_with_pp_button_type) { diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index 858d1f9b4..6fbabef95 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -832,6 +832,13 @@ function angelleye_product_type_options_own($product_type){ 'description' => __( '', 'paypal-for-woocommerce' ), 'default' => 'no' ); + $product_type['enable_ec_button'] = array( + 'id' => '_enable_ec_button', + 'wrapper_class' => '', + 'label' => __( 'Enable Express Checkout Button', 'paypal-for-woocommerce' ), + 'description' => __( '', 'paypal-for-woocommerce' ), + 'default' => 'no' + ); return $product_type; } else { return $product_type; @@ -845,6 +852,8 @@ function angelleye_woocommerce_process_product_meta_own( $post_id ){ update_post_meta( $post_id, '_paypal_billing_agreement', $_paypal_billing_agreement ); $_enable_sandbox_mode = isset( $_POST['_enable_sandbox_mode'] ) ? 'yes' : 'no'; update_post_meta( $post_id, '_enable_sandbox_mode', $_enable_sandbox_mode ); + $_enable_ec_button = isset( $_POST['_enable_ec_button'] ) ? 'yes' : 'no'; + update_post_meta( $post_id, '_enable_ec_button', $_enable_ec_button ); } public static function angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = null, $gateway = null, $error_email_notify = true) { @@ -947,6 +956,8 @@ public function angelleye_woocommerce_pfw_ed_shipping_bulk_tool() { } elseif ($pfw_bulk_action_type == 'enable_paypal_billing_agreement' || $pfw_bulk_action_type == 'disable_paypal_billing_agreement') { $action_key = "_paypal_billing_agreement"; + } elseif ($pfw_bulk_action_type == 'enable_express_checkout_button' || $pfw_bulk_action_type == 'disable_express_checkout_button') { + $action_key = "_enable_ec_button"; } // All Products diff --git a/template/admin.php b/template/admin.php index e7ebd2553..5f1b21c7f 100644 --- a/template/admin.php +++ b/template/admin.php @@ -114,27 +114,29 @@ } ?> wc_get_log_file_path('paypal_credit_card_rest'), - 'braintree' => wc_get_log_file_path( 'braintree' ), - 'paypal_advanced' => wc_get_log_file_path( 'paypal_advanced' ), - 'paypal_express' => wc_get_log_file_path( 'paypal_express' ), - 'paypal-pro' => wc_get_log_file_path( 'paypal-pro' ), - 'paypal_payflow' => wc_get_log_file_path( 'paypal_payflow' ) - ); - $count = 0; - foreach ($paypal_for_woocommerce_logfile_path as $key => $value) { - if ( file_exists( $value ) ) { - unlink( $value ); - $count = $count + 1; + if( isset($_GET['_paypal_for_woocommerce_remove_log_file'])) { + if ( !empty( $_GET['_paypal_for_woocommerce_remove_log_file'] ) || wp_verify_nonce( $_GET['_paypal_for_woocommerce_remove_log_file'], 'paypal-for-woocommerce-remove-log-file' ) ) { + $paypal_for_woocommerce_logfile_path = array('paypal_credit_card_rest' => wc_get_log_file_path('paypal_credit_card_rest'), + 'braintree' => wc_get_log_file_path( 'braintree' ), + 'paypal_advanced' => wc_get_log_file_path( 'paypal_advanced' ), + 'paypal_express' => wc_get_log_file_path( 'paypal_express' ), + 'paypal-pro' => wc_get_log_file_path( 'paypal-pro' ), + 'paypal_payflow' => wc_get_log_file_path( 'paypal_payflow' ) + ); + $count = 0; + foreach ($paypal_for_woocommerce_logfile_path as $key => $value) { + if ( file_exists( $value ) ) { + unlink( $value ); + $count = $count + 1; + } } + $remove_logfile_tool_url = remove_query_arg( '_paypal_for_woocommerce_remove_log_file' ); + wp_redirect( esc_url_raw( add_query_arg( 'count', $count, $remove_logfile_tool_url ) ) ); + exit; + } + if( !empty($_GET['count']) && $_GET['count'] > 0) { + echo '

' . __( 'Logfile has been successfully deleted.', 'paypal-for-woocommerce' ) . '

'; } - $remove_logfile_tool_url = remove_query_arg( '_paypal_for_woocommerce_remove_log_file' ); - wp_redirect( esc_url_raw( add_query_arg( 'count', $count, $remove_logfile_tool_url ) ) ); - exit; - } - if( !empty($_GET['count']) && $_GET['count'] > 0) { - echo '

' . __( 'Logfile has been successfully deleted.', 'paypal-for-woocommerce' ) . '

'; } ?> @@ -153,6 +155,8 @@ + +
@@ -238,7 +242,7 @@

-

+