From 70fd8f24d8663053ee581cbfffe07275d6c7b1a0 Mon Sep 17 00:00:00 2001 From: jigneshkaila Date: Wed, 17 Jun 2015 11:58:17 +0530 Subject: [PATCH] Express Checkout - Digital / Virtual Goods - NOSHIPPING Global, ref #175 --- paypal-for-woocommerce.php | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index 30c688d52..524aed097 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -82,6 +82,11 @@ public function __construct() add_action( 'woocommerce_cart_calculate_fees', array($this, 'woocommerce_custom_surcharge') ); add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_div_before_add_to_cart_button' ), 25); add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'add_div_after_add_to_cart_button' ), 35); + add_action('admin_footer-edit.php', array( $this, 'angelleye_bulk_admin_footer'), 11); + add_action('load-edit.php', array( $this, 'angelleye_bulk_action' ), 11 ); + add_action('admin_notices', array( $this, 'angelleye_bulk_admin_notices' ) ); + //add_filter( 'bulk_actions-edit-product', array( $this, 'my_custom_bulk_actions' ), 11 ); + } /** @@ -559,6 +564,121 @@ function add_div_after_add_to_cart_button(){ + + current_action(); + $post_ids = (isset($_REQUEST['post']) ) ? $_REQUEST['post'] : FALSE; + if($post_ids) { + switch ($action) { + case 'enable_shipping_address_for_all_products': + $updated_count = 0; + foreach ($post_ids as $post_id) { + update_post_meta( $post_id, '_no_shipping_required', 'true'); + $updated_count++; + } + $sendback = add_query_arg(array('enable_shipping_address_for_all_products' => $updated_count, 'ids' => join(',', $post_ids)), 'edit.php?post_type=product'); + $sendback = esc_url_raw($sendback); + break; + case 'disable_shipping_address_for_all_products': + $updated_count = 0; + foreach ($post_ids as $post_id) { + update_post_meta( $post_id, '_no_shipping_required', 'false'); + $updated_count++; + } + $sendback = add_query_arg(array('disable_shipping_address_for_all_products' => $updated_count, 'ids' => join(',', $post_ids)), 'edit.php?post_type=product'); + $sendback = esc_url_raw($sendback); + break; + case 'enable_shipping_address_for_downloadable_products': + $updated_count = 0; + foreach ($post_ids as $post_id) { + update_post_meta( $post_id, '_no_shipping_required', 'true'); + $updated_count++; + } + $sendback = add_query_arg(array('enable_shipping_address_for_downloadable_products' => $updated_count, 'ids' => join(',', $post_ids)), 'edit.php?post_type=product'); + $sendback = esc_url_raw($sendback); + break; + case 'disable_shipping_address_for_downloadable_products': + $updated_count = 0; + foreach ($post_ids as $post_id) { + update_post_meta( $post_id, '_no_shipping_required', 'false'); + $updated_count++; + } + $sendback = add_query_arg(array('disable_shipping_address_for_downloadable_products' => $updated_count, 'ids' => join(',', $post_ids)), 'edit.php?post_type=product'); + $sendback = esc_url_raw($sendback); + break; + case 'enable_shipping_address_for_virtual_products': + $updated_count = 0; + foreach ($post_ids as $post_id) { + update_post_meta( $post_id, '_no_shipping_required', 'true'); + $updated_count++; + } + $sendback = add_query_arg(array('enable_shipping_address_for_virtual_products' => $updated_count, 'ids' => join(',', $post_ids)), 'edit.php?post_type=product'); + $sendback = esc_url_raw($sendback); + break; + case 'disable_shipping_address_for_virtual_products': + $updated_count = 0; + foreach ($post_ids as $post_id) { + update_post_meta( $post_id, '_no_shipping_required', 'false'); + $updated_count++; + } + $sendback = add_query_arg(array('disable_shipping_address_for_virtual_products' => $updated_count, 'ids' => join(',', $post_ids)), 'edit.php?post_type=product'); + $sendback = esc_url_raw($sendback); + break; + default: + return; + } + wp_redirect($sendback); + exit(); + } + + } + + public function angelleye_bulk_admin_notices() { + global $post_type, $pagenow; + + if($pagenow == 'edit.php' && $post_type == 'product' && isset($_REQUEST['enable_shipping_address_for_all_products']) && (int) $_REQUEST['enable_shipping_address_for_all_products'] && ($_REQUEST['enable_shipping_address_for_all_products'] > 0)) { + $message = sprintf( __( 'Shipping Address enabled for %s products.', $this->plugin_slug ), number_format_i18n( $_REQUEST['enable_shipping_address_for_all_products'] ) ); + echo '

'.$message.'

'; + } + + } + + public function my_custom_bulk_actions($actions) { + unset($actions['edit']); + return $actions; + } + + } } new AngellEYE_Gateway_Paypal(); \ No newline at end of file