diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..1f63f01 --- /dev/null +++ b/readme.txt @@ -0,0 +1,49 @@ +=== Woocommerce Quick Buy === +Contributors: varunms +Author URI: http://varunsridharan.in/ +Plugin URL: https://wordpress.org/plugins/woocommerce-quick-buy/ +Tags: Woocommerce,wc,Quick buy,add to cart +Donate link: http://varunsridharan.in +Requires at least: 3.0 plus WooCommerce 2.x +Tested up to: 4.0.1 + WooCommerce 2.x +Stable tag: 0.1 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +Adds Quick Buy Button In Single Cart Page in Woocommerce. + +== Description == +Adds Quick Buy Button In Single Cart Page in Woocommerce. + +When User Clicks This Button. The Current product Will Be Added To Cart And The User Will Be Redirected To Cart Page + + +**Settings Avaiable Under** + +Woocommerce Settings ==> Products ==> WC Quick Buy + +**Add Short Code While In Product Loop** +`[wc_quick_buy]` + +**Add Short Code With Product ID** +`[wc_quick_buy product="1"]` + +== Installation == +1. Installing alternatives: + * *via Admin Dashboard:* Go to \'Plugins > Add New\', search for \"WooCommerce Quick Buy\", click \"install\" + * *OR via direct ZIP upload:* Upload the ZIP package via \'Plugins > Add New > Upload\' in your WP Admin + * *OR via FTP upload:* Upload `woocommerce-quick-buy` folder to the `/wp-content/plugins/` directory +2. Activate the plugin through the \'Plugins\' menu in WordPress +3. For Settings Look at your `Woocommerce => Settings => Product => WC Quick Buy` + +== Frequently Asked Questions == +**I have an idea for your plugin!** +That\\'s great. We are always open to your input, and we would like to add anything we think will be useful to a lot of people. Please send your comment/idea to varunsridharan23@gmail.com + +**I found a bug!** +Oops. Please User github / WordPress to post bugs. Open an Issue + +== Changelog == + += 0.1 = +* Base Version \ No newline at end of file diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 0000000..805c424 --- /dev/null +++ b/uninstall.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/woocommerce-quick-buy.php b/woocommerce-quick-buy.php new file mode 100644 index 0000000..d9612df --- /dev/null +++ b/woocommerce-quick-buy.php @@ -0,0 +1,196 @@ +settings = array(); + $this->get_db_data(); + } + + private function get_db_data(){ + $this->settings['lable'] = get_option('wc_quick_buy_lable'); + $this->settings['position'] = get_option('wc_quick_buy_position'); + $this->settings['class'] = get_option('wc_quick_buy_class'); + $this->settings['automatic'] = get_option('wc_quick_buy_auto'); + + if(isset($this->settings['automatic']) && $this->settings['automatic'] == 'true'){ + if(! empty($this->settings['position']) && ! $this->settings['position'] == null){ + add_action ('woocommerce_'.$this->settings['position'].'_add_to_cart_form',array($this,'wc_quick_buy_after_add_to_cart_form_add'),99); + } + } + + } + + + + /*** + * Create the section beneath the products tab + */ + public function wc_quick_buy_add_section( $sections ) { + $sections['wc_quick_buy'] = __( 'WC Quick Buy', 'text-domain' ); + return $sections; + } + + public function install(){ + add_option('wc_quick_buy_auto','true'); + add_option('wc_quick_buy_position','after'); + add_option('wc_quick_buy_lable','Quick Buy'); + add_option('wc_quick_buy_class','quick_buy_button'); + } + + + /*** + * Add settings to the specific section we created before + */ + public function wc_quick_buy_all_settings( $settings, $current_section ) { + if ( $current_section == 'wc_quick_buy' ) { + $wc_quick_buy = array(); + $wc_quick_buy[] = array( 'name' => __( 'WC Quick Buy Settings', 'text-domain' ), + 'type' => 'title', + 'desc' => __( 'The following options are used to configure WC Quick Buy', 'text-domain' ), + 'id' => 'wc_quick_buy' ); + $wc_quick_buy[] = array( + 'name' => __( 'Automatically Add Button ', 'text-domain' ), + 'desc_tip' => __( 'Automaticaly Adds Button After Add To Cart In Single Product View', 'text-domain' ), + 'id' => 'wc_quick_buy_auto', + 'type' => 'select', + 'class' =>'chosen_select', + 'options' => array('true' => 'Yes','false'=>'No') + ); + $wc_quick_buy[] = array( + 'name' => __( 'Position', 'text-domain' ), + 'desc_tip' => __( 'Where the button need to be added in single page .. before / after', 'text-domain' ), + 'id' => 'wc_quick_buy_position', + 'type' => 'select', + 'class' =>'chosen_select', + 'options' => array('after' => 'After Add To Cart','before'=>'Before Add To Cart') + ); + $wc_quick_buy[] = array( + 'name' => __( 'Quick Buy Button Text', 'text-domain' ), + 'desc_tip' => __( 'You Can Change The Quick Buy Button Lable', 'text-domain' ), + 'id' => 'wc_quick_buy_lable', + 'type' => 'text', + ); + $wc_quick_buy[] = array( + 'name' => __( 'Quick Buy Button Class', 'text-domain' ), + 'desc_tip' => __( 'You Can Change The Quick Buy Button Class', 'text-domain' ), + 'id' => 'wc_quick_buy_class', + 'type' => 'text', + ); + + $wc_quick_buy[] = array( 'type' => 'sectionend', 'id' => 'wc_quick_buy' ); + + $wc_quick_buy[] = array( 'name' => __( 'WC Quick Buy Short Code', 'text-domain' ), + 'type' => 'title', + 'desc' => __( 'You can also use [wc_quick_buy] short code to call where ever you want in your template
you can also set product id manually by [wc_quick_buy product="2"] + + ', 'text-domain' ), + 'id' => 'wc_quick_buy_shortcode' ); + return $wc_quick_buy; + } else { + return $settings; + } + } + + + public function wc_quick_buy_add_to_cart_redirect_check(){ + if(isset($_REQUEST['quick_buy']) && $_REQUEST['quick_buy'] == true){ + wp_safe_redirect(WC()->cart->get_cart_url() ); + exit; + } + return ''; + } + + public function wc_quick_buy_after_add_to_cart_form_add(){ + global $product; + + if($product->is_type( 'simple' )){ + echo $this->wc_quick_buy_add_quick_buy_form($product->id); + } + + } + + + + public function wc_quick_buy_shortcode_handler($product) { + $prod = shortcode_atts( array('product' => null), $product ); + if($prod['product'] == null){ + global $product; + + if($product->is_type( 'simple' )){ + echo $this->wc_quick_buy_add_quick_buy_form($product->id); + } + } else { + $product = get_product($a['product']); + if($product->is_type( 'simple' )){ + echo $this->wc_quick_buy_add_quick_buy_form($product->id); + } + } + } + + + + public function wc_quick_buy_add_quick_buy_form($productid){ + + $form = '
+ + + + +
'; + return $form; + } + + + public function update_settings() { + woocommerce_update_options( get_settings() ); + } + +} + + + + + +/** + * Check if WooCommerce is active + * if yes then call the class + */ +if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { + register_activation_hook( __FILE__, array( 'wc_quick_buy', 'install' ) ); + $wc_quick_buy = new wc_quick_buy; +} + + +?> \ No newline at end of file