diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index e7140f16a..7ff0b886f 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -103,6 +103,10 @@ public function __construct() add_action( 'admin_menu', array( $this, 'angelleye_admin_menu_own' ) ); add_action( 'product_type_options', array( $this, 'angelleye_product_type_options_own' ), 10, 1); add_action( 'woocommerce_process_product_meta', array( $this, 'angelleye_woocommerce_process_product_meta_own' ), 10, 1 ); + 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 ); } /** @@ -1085,6 +1089,149 @@ public static function angelleye_paypal_for_woocommerce_curl_error_handler($PayP throw new Exception($PayPalResult['CURL_ERROR']); } } + + /** + * PayPal for WooCommerce bulk action for enable/disable shipping address + * Express Checkout - Digital / Virtual Goods - NOSHIPPING Global #175 + * @since 1.1.8 + */ + public function angelleye_bulk_admin_footer() { + global $post_type; + if($post_type == 'product') { + ?> + + $enable_disable_shipping_action_value) { + if($pagenow == 'edit.php' && $post_type == 'product' && isset($_REQUEST[$enable_disable_shipping_action_value])) { + $message = sprintf( __( 'Shipping Address enabled for %s products.', $this->plugin_slug ), number_format_i18n( $_REQUEST[$enable_disable_shipping_action_value] ) ); + echo '

'.$message.'

'; + break; + } + } + } + + /** + * Express Checkout - Digital / Virtual Goods - NOSHIPPING Global #175 + * @return type + * @since 1.1.8 + */ + public function angelleye_bulk_action() { + $wp_list_table = _get_list_table('WP_Posts_List_Table'); + $action = $wp_list_table->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) { + $product = get_product( $post_id ); + if( $product->is_type( 'downloadable' ) ){ + 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) { + $product = get_product( $post_id ); + if( $product->is_type( 'downloadable' ) ){ + 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) { + $product = get_product( $post_id ); + if( $product->is_type( 'virtual' ) ){ + 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) { + $product = get_product( $post_id ); + if( $product->is_type( 'virtual' ) ){ + 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(); + } + } + + /** + * Express Checkout - Digital / Virtual Goods - NOSHIPPING Global #175 + * @param type $actions + * @return type + * @since 1.1.8 + */ + public function my_custom_bulk_actions($actions) { + unset($actions['edit']); + return $actions; + } } } new AngellEYE_Gateway_Paypal(); \ No newline at end of file