Plugin Directory

Changeset 2290193


Ignore:
Timestamp:
04/23/2020 03:03:00 PM (6 years ago)
Author:
milardovich
Message:

Version 1.0.2 released

Location:
pre-orders-for-woocommerce
Files:
297 added
6 edited

Legend:

Unmodified
Added
Removed
  • pre-orders-for-woocommerce/trunk/main.php

    r2281172 r2290193  
    22/**
    33 * Plugin Name: Preoders for WooCommerce
    4  * Plugin URI: https://brightplugins.com/woocommerce-preorder-plugin-review/
     4 * Plugin URI: https://brightplugins.com/
    55 * Description: Ultimate Preorders Plugin for WooCommerce.
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Author: Bright Plugins
    88 * Author URI: https://brightplugins.com
    99 * Text Domain: preorders-woocommerce
    10  * Domain Path: /etc/i18n/languages/
    11  *
    12  * @package WooCommercePreOrders
     10 * Domain Path: /etc/i18n/languages/.
    1311 */
    14 
    1512defined('ABSPATH') || exit;
    1613
     
    2017}
    2118
     19use Woocommerce_Preorders\Bootstrap;
    2220use Woocommerce_Preorders\Packages;
    23 use Woocommerce_Preorders\Bootstrap;
    2421
    25 /**
    26  * Check if WooCommerce is active
    27  **/
    28 if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
     22// Check if WooCommerce is active
     23if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')), true)) {
    2924    // Put your plugin code here
    3025
    3126    add_action('woocommerce_loaded', function () {
    32         require_once WCPO_PLUGIN_DIR . '/vendor/autoload.php';
    33         require_once WCPO_PLUGIN_DIR . '/etc/conf.php';       
     27        require_once WCPO_PLUGIN_DIR.'/vendor/autoload.php';
     28        require_once WCPO_PLUGIN_DIR.'/etc/conf.php';
    3429
    3530        $bootstrap = new Bootstrap();
    3631        register_activation_hook(__FILE__, [$bootstrap, 'defaultOptions']);
    37        
     32
    3833        $package = new Packages();
    39 
    4034    });
    4135} else {
    4236    add_action('admin_notices', function () {
    4337        $class = 'notice notice-error';
    44         $message = __( 'Oops! looks like WooCommerce is disabled. Please, enable it in order to use WooCommerce Pre-Orders.', 'preorders' );
    45         printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
     38        $message = __('Oops! looks like WooCommerce is disabled. Please, enable it in order to use WooCommerce Pre-Orders.', 'preorders');
     39        printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
    4640    });
    4741}
  • pre-orders-for-woocommerce/trunk/readme.txt

    r2281175 r2290193  
    1 === Preorders for WooCommerce ===
     1=== Pre-orders for WooCommerce ===
    22Contributors: brightvesseldev, milardovich
    33Requires at least: 5.0
    44Tested up to: 5.4
    55Requires PHP: 7.0
    6 Stable tag: 1.0.1
     6Stable tag: 1.0.2
    77License: GPLv3
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    1212== Description ==
    1313
    14 Preorders for WooCommerce Plugin - Free Version
     14An efficient system that easily translates to the specific needs of store, our plugin allows you to follow up on pre-sales in a comprehensive way.
    1515
    16 Do you need to accept Preorders on your WooCommerce site?
     16The wait for a new product (or the return of a popular one) is a great opportunity to gain new customers or engage older ones. However, too many companies misuse this unique time until customers lose interest. Engaging is critical in the days before a product release, which is why we’ve created a plugin that covers all bases. Give customers a chance to pre-order so they’ll get their new item just as it becomes available, letting you monitor each step of the way.
     17Here’s what you can do with the Bright Plugins WooCommerce Pre-Order Plugin:
    1718
    18 There are many benefits in offering preorders which can help businesses in several ways. A preorder is when a company offers customers a product that's not yet manufactured or on sale.
     19* Manage all pre-orders through a specialized section on My Account.
     20* Set up a “pre-order” status for both simple and variable products.
     21* Create an expiration date for pre-order periods.
     22* Filter all orders that include products ordered during the “pre-order” phase.
     23* Automatically turn products that are out of stock into pre-orders.
     24* Make products available automatically as soon as the pre-order period ends.
     25* Prevent customers from adding pre-order products when they have already-available items on their carts.
     26* Edit single product prices during the pre-order period: fixed, percentage or markup on the base price.
     27* Apply “pre-order” status to more than one product through a WordPress Bulk action grouped by tag or category.
     28* Enable the pre-order option for a variable product, in the case that every variation was previously added to the pre-order status.
     29* Notify website admins when products’ pre-order periods are nearing their ends, emailing them a set amount of days before the date.
     30* Notify users when products’ pre-order periods are over and they’ve become fully available.
    1931
    20 Bright Vessel’s decision to build a better plugin then what is currently available for allowing WooCommerce store owners to add preorder products to their website.
     32**Our plugin supports 4 different business cases. Only case #4 is available in this free version. If you need any of the other cases, please [buy a pro license](https://brightplugins.com/woocommerc-preorder-plugin/).**
    2133
    22 **Here are a few main reasons why you should have Preorders on your website:**
     34**Case #1 – Treat the whole order as a pre-order**
    2335
    24 * Limited edition products, such as Christmas or special editions
    25 * New flagship products for your company
    26 * New businesses launching into the market
    27 * Special promotions or discounts on an already-existing product
    28 * Supply chain slow in restocking
    29 * Basic Features in Free Version:
    30 * Create a preorder product.
    31 * Allow customers to choose between buying preorder products or available ones
    32 * Premium Features in Paid Version
    33 * Separate shipping methods for available and preorder products.
    34 * Separate orders between preordered and available products.
     36If you choose this mode, the customer will be able to select a shipping date, and all products will be shipped together at that specific day.
    3537
     38That day will be limited to the latest pre-order date available, for instance, if the order has 3 different products marked as pre-order ones:
    3639
    37 [Purchase Preorders for WooCommerce Plugin Premium Version.](https://share.brightvessel.com/MAA "PRO version.")
     40    Product A will be available on the 1st of September
     41    Product B will be available on the 3rd of September
     42    Product C will be available on the 1st of October
    3843
    39 *Modes:*
     44Then, the minimum shipping date will be the 1st of October (i.e: the minimum date when all products will be available).
     45Link to: Wordpress and WooCommerce Management
    4046
    41 *Free Version:*
     47**Case #2 – Generate two separate orders, one for pre-orders and one for in-stock products**
    4248
    43 **#1 - Treat the whole order as a preorder**
     49If you choose this mode, the customer will get two different orders generated, one for pre-order products and one for in-stock ones. For instance, if your order looks like this:
    4450
    45 If you choose this mode, the customer will be able to select a shipping date, and all products will be shipped together on that specific day.
     51    Product A is in-stock
     52    Product B will be available on the 1st of September
     53    Product C is in-stock
    4654
    47 Note: In this mode, only preorder products can be ordered. You cannot mix normal products and preorders products
     55Then you will get an order which will be processed now, with products A and C, and then another order which will be shipped on the 1st of September.
     56Link to: Wordpress and WooCommerce Management
    4857
     58**Case #3 – Generate separate orders for each pre-order products**
    4959
    50 *Premium Version:*
     60If you choose this mode, then the customer will get one order for all in-stock products, and then one order for each pre-order product which will be shipped in each specific pre-order date.
     61Link to: Wordpress and WooCommerce Management
    5162
    52 **#2 - Generate two separate orders, one for preorders and one for in-stock products**
     63**Case #4 – Allow only pre-orders**
    5364
    54 If you choose this mode, the customer will get two different orders generated, one for preorder products and one for in-stock ones.
     65Use this mode if you want to only allow your customers to either choose pre-order products or available ones.
     66Some other preorder features we offer:
    5567
    56 **#3 - Generate separate orders for each preorder products**
     68    Pick an optional date and time when the product will be available for purchase
     69    When products are available, admin can set to automatically charge
     70    Set and Change release dates for preorder products
     71    Email feature that allows admins to notify all customers who pre-ordered a product
     72    If products are no longer available, current preorders can be canceled.
     73    Easily filter through all preorders with a custom order status
     74    Compatible with simple and variant products
     75    Optional feature to allow for an additional charge for preorders
     76    Customize the text on the add to cart buttons for preorders
    5777
    58 If you choose this mode, then the customer will get one order for all in-stock products, and then one order for each preorder product, which will be shipped in each specific preorder date.
    59 
    60 **#4 - Allow only preorders**
    61 
    62 Use this mode if you want to only allow your customers to either choose preorder products or available ones.
    63 
    64 
    65 [Here is a PDF user’s guide.](https://share.brightvessel.com/M4r "user’s guide.")
    66 
    67 [Here is the online documentation.](https://share.brightvessel.com/MVy "online documentation.")
    68 
    69 Have any ideas on how we can improve the plugin? Don’t hesitate to share it [here](https://share.brightvessel.com/MAb "here") and we will try to implement it in future versions of the plugin.
    70 
    71 Do you like the plugin and want to say about it?
    7278
    7379
  • pre-orders-for-woocommerce/trunk/src/Bootstrap.php

    r2281061 r2290193  
    1313
    1414        $this->generatePreOrderStatus();
     15
     16        //$this->compatibilityCheck();
    1517
    1618        // add_action('woocommerce_thankyou', [$checkout, 'checkGeneratedOrderStatus']);
     
    4042            if (!get_option($option) || '' === get_option($option)) {
    4143                add_option($option, $value);
     44            }
     45        }
     46    }
     47
     48    public function compatibilityCheck()
     49    {
     50        // Check if the free version is enabled, and if so, disable it
     51        if (in_array('preorders-for-woocommerce/main.php', apply_filters('active_plugins', get_option('active_plugins')), true)) {
     52            $license = new License();
     53            if ($license->isValid()) {
     54                deactivate_plugins('preorders-for-woocommerce/main.php');
    4255            }
    4356        }
  • pre-orders-for-woocommerce/trunk/src/Checkout.php

    r2281061 r2290193  
    1313
    1414        $this->cart = new Cart();
    15         if($this->preordersMode == 'either')
    16             add_filter( 'woocommerce_add_to_cart_validation', [$this->cart, 'allowOneTypeOnly'], 99, 2 );
     15        if ('either' === $this->preordersMode) {
     16            add_filter('woocommerce_add_to_cart_validation', [$this->cart, 'allowOneTypeOnly'], 99, 2);
     17        }
    1718
    1819        add_filter('woocommerce_billing_fields', [$this, 'addShippingDateField']);
    1920
    20         if (!in_array(get_option('wc_preorders_mode'),['whole','either'])) {
     21        if (!\in_array(get_option('wc_preorders_mode'), ['whole', 'either'], true)) {
    2122            add_action('woocommerce_thankyou', [$this, 'purgePreOrderedItems'], 9999, 1);
    2223        } else {
     
    3233    public function addShippingDateField($fields)
    3334    {
    34         if (get_option('wc_preorders_always_choose_date') == 'no') {
     35        if (!is_checkout() && !is_cart()) {
     36            return $fields;
     37        }
     38        if ('no' === get_option('wc_preorders_always_choose_date')) {
    3539            $class = ['disabled-input', 'form-row-wide'];
    3640        } else {
     
    4044        $cart = $woocommerce->cart->get_cart();
    4145        $this->cart->checkPreOrderProducts($cart);
    42         if (count($this->cart->getPreOrderProducts()) > 0) {
     46        if (\count($this->cart->getPreOrderProducts()) > 0) {
    4347            $fields['preorder_date'] = [
    4448                'label' => __('Pre order Date', 'preorder'),
     
    5054                'required' => true,
    5155                'default' => $this->cart->getOldestDate(),
    52                 'custom_attributes' => ['data-pre_order_date' => $this->cart->getOldestDate()]
     56                'custom_attributes' => ['data-pre_order_date' => $this->cart->getOldestDate()],
    5357            ];
    5458        }
     
    5761    }
    5862
    59     private function getPreorderedProducts($order)
    60     {
    61         $preorderedProducts = [];
    62         foreach ($order->get_items() as $item) {
    63             $productId = 0 !== $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
    64             $isPreOrder = get_post_meta($productId, '_pre_order_date', true);
    65             if ($isPreOrder && strtotime($isPreOrder) > time()) {
    66                 $preorderedProducts[] = $item;
    67             }
    68         }
    69         return $preorderedProducts;
    70     }
    71 
    7263    public function manageShippingCosts($rates, $package)
    7364    {
    7465        $factor = 1;
    75         if ($this->preordersMode == 'individual') {
     66        if ('individual' === $this->preordersMode) {
    7667            /*
    7768            * If we are on "individual" mode, then we will have to multiply it by the number of
     
    8172            $cart = $woocommerce->cart->get_cart();
    8273            $this->cart->checkPreOrderProducts($cart);
    83             if (count($this->cart->getPreOrderProducts()) > 0) {
    84                 $factor = 1+count($this->cart->getPreOrderProducts());
     74            if (\count($this->cart->getPreOrderProducts()) > 0) {
     75                $factor = 1 + \count($this->cart->getPreOrderProducts());
    8576            }
    86         } elseif ($this->preordersMode == 'partial') {
     77        } elseif ('partial' === $this->preordersMode) {
    8778            /*
    8879            * If we are in partial mode and the "multiply shipping" option is enabled,
     
    9485            $rates[$id]->cost *= $factor;
    9586        }
    96        
    9787
    9888        return $rates;
     
    10898         * as whole. Check our docs for more info.
    10999         */
    110         if (($this->preordersMode == 'partial' && count($order->get_items()) == count($this->cart->getPreOrderProducts())) || ($this->preordersMode == 'individual' && count($order->get_items()) == count($this->cart->getPreOrderProducts()) && count($order->get_items()) == 1)) {
     100        if (('partial' === $this->preordersMode && \count($order->get_items()) === \count($this->cart->getPreOrderProducts())) || ('individual' === $this->preordersMode && \count($order->get_items()) === \count($this->cart->getPreOrderProducts()))) {
    111101            $this->preordersMode = 'whole';
    112102        }
     
    136126         * Check our docs for more info.
    137127         */
    138         if ($this->preordersMode !== 'whole') {
     128        if ('whole' !== $this->preordersMode) {
    139129            $preorderedProducts = $this->getPreorderedProducts($order);
    140            
    141130
    142131            /*
     
    154143        }
    155144
    156         /*
    157          * Calculate shipping split factor
    158          */
     145        // Calculate shipping split factor
    159146        $factor = $this->getSplitShippingFactor($order);
    160147
     
    175162                $preorder->set_address($shippingAddress, 'shipping');
    176163
    177 
    178164                $shippingMethod = $order->get_items('shipping')[array_keys($order->get_items('shipping'))[1]]->get_data();
    179                 $shippingMethodCurated = new \WC_Shipping_Rate($shippingMethod['id'], $shippingMethod['method_title'], $shippingMethod['total']/$factor, $shippingMethod['total_tax']/$factor, $shippingMethod['method_id'], $shippingMethod['instance_id']);
     165                $shippingMethodCurated = new \WC_Shipping_Rate($shippingMethod['id'], $shippingMethod['method_title'], $shippingMethod['total'] / $factor, $shippingMethod['total_tax'] / $factor, $shippingMethod['method_id'], $shippingMethod['instance_id']);
    180166                $preorder->add_shipping($shippingMethodCurated);
    181167
     
    189175
    190176                $order->remove_item(array_keys($order->get_items('shipping'))[1]);
     177
    191178            break;
    192 
    193179            /*
    194180             * Case #3: generate one order for all in-stock products, and then one order for each pre-order product
     
    196182             */
    197183            case 'individual':
    198                 /*
    199                  * TODO: we are repeating too much code between cases #2 and #3
    200                  */
    201                 $i=1;
     184                // TODO: we are repeating too much code between cases #2 and #3
     185                $i = 1;
    202186                foreach ($preorderedProducts as $product) {
    203187                    $preorder = wc_create_order();
     
    207191                    $preorder->set_address($shippingAddress, 'shipping');
    208192
    209 
    210193                    $shippingMethod = $order->get_items('shipping')[array_keys($order->get_items('shipping'))[$i]]->get_data();
    211                     $shippingMethodCurated = new \WC_Shipping_Rate($shippingMethod['id'], $shippingMethod['method_title'], $shippingMethod['total']/$factor, $shippingMethod['total_tax']/$factor, $shippingMethod['method_id'], $shippingMethod['instance_id']);
     194                    $shippingMethodCurated = new \WC_Shipping_Rate($shippingMethod['id'], $shippingMethod['method_title'], $shippingMethod['total'] / $factor, $shippingMethod['total_tax'] / $factor, $shippingMethod['method_id'], $shippingMethod['instance_id']);
    212195                    $preorder->add_shipping($shippingMethodCurated);
    213196
     
    221204                     * date for the chose date. Otherwise get that info from each product.
    222205                     */
    223                     if (get_option('wc_preorders_always_choose_date') == 'yes') {
     206                    if ('yes' === get_option('wc_preorders_always_choose_date')) {
    224207                        $preorder->update_meta_data('_preorder_date', $data['preorder_date']);
    225208                    } else {
     
    229212
    230213                    $preorder->update_meta_data('_payment_method', get_post_meta($orderId, '_payment_method', true));
    231                     $preorder->update_meta_data('_payment_method_title',get_post_meta($orderId,'_payment_method',true));
    232                     $preorder->update_meta_data('_created_via',get_post_meta($orderId,'_created_via',true));
    233                     $preorder->update_meta_data('_date_paid',get_post_meta($orderId,'_date_paid',true));
    234                     $preorder->update_meta_data('_paid_date',get_post_meta($orderId,'_paid_date',true));
     214                    $preorder->update_meta_data('_payment_method_title', get_post_meta($orderId, '_payment_method', true));
     215                    $preorder->update_meta_data('_created_via', get_post_meta($orderId, '_created_via', true));
     216                    $preorder->update_meta_data('_date_paid', get_post_meta($orderId, '_date_paid', true));
     217                    $preorder->update_meta_data('_paid_date', get_post_meta($orderId, '_paid_date', true));
    235218
    236219                    $preorder->save();
    237                     $i++;
     220                    ++$i;
    238221                }
    239222
    240                 $i=0;
     223                $i = 0;
    241224                foreach ($order->get_items('shipping') as $key => $shippingMethods) {
    242                     if($i>0){
     225                    if ($i > 0) {
    243226                        $order->remove_item($key);
    244227                    }
    245                     $i++;
     228                    ++$i;
    246229                }
    247230
     
    254237                if (isset($data['preorder_date'])) {
    255238                    $order->update_meta_data('_preorder_date', $data['preorder_date']);
    256                     $preorder->set_status('wc-pre-ordered');
     239                    $order->set_status('wc-pre-ordered');
    257240                }
     241
    258242                break;
    259243        }
     
    268252        $items = $order->get_data();
    269253        $this->cart->checkPreOrderProducts($items);
    270         if (count($this->cart->getPreOrderProducts()) > 0) {
     254        if (\count($this->cart->getPreOrderProducts()) > 0) {
    271255            $order->update_status('pre-ordered');
    272256        }
     
    284268        $diff = 0;
    285269        foreach ($items as $key => $product) {
    286             if (('yes' == get_post_meta($product->get_product_id(), '_is_pre_order', true) && strtotime(get_post_meta($product->get_product_id(), '_pre_order_date', true)) > time()) || 'yes' == get_post_meta($product->get_variation_id(), '_is_pre_order', true) && strtotime(get_post_meta($product->get_variation_id(), '_pre_order_date', true)) > time()) {
     270            if (('yes' === get_post_meta($product->get_product_id(), '_is_pre_order', true) && strtotime(get_post_meta($product->get_product_id(), '_pre_order_date', true)) > time()) || 'yes' === get_post_meta($product->get_variation_id(), '_is_pre_order', true) && strtotime(get_post_meta($product->get_variation_id(), '_pre_order_date', true)) > time()) {
    287271                $deleteKeys[] = wc_delete_order_item($key);
    288272                $diff += $product->get_total();
     
    290274        }
    291275        $newTotal = $order->calculate_totals() - $diff;
    292 
    293276
    294277        $order->set_total($newTotal);
     
    304287        }
    305288    }
    306    
    307     /*
    308     * Get the shipping total and split it into the amount of orders generated
    309     */
     289
     290    private function getPreorderedProducts($order)
     291    {
     292        $preorderedProducts = [];
     293        foreach ($order->get_items() as $item) {
     294            $productId = 0 !== $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
     295            $isPreOrder = get_post_meta($productId, '_pre_order_date', true);
     296            if ($isPreOrder && strtotime($isPreOrder) > time()) {
     297                $preorderedProducts[] = $item;
     298            }
     299        }
     300
     301        return $preorderedProducts;
     302    }
     303
     304    // Get the shipping total and split it into the amount of orders generated
    310305    private function getSplitShippingFactor($order)
    311306    {
    312         if (get_option('wc_preorders_multiply_shipping') !== 'yes') {
     307        if ('yes' !== get_option('wc_preorders_multiply_shipping')) {
    313308            return 1;
    314309        }
    315310
    316         /*
    317          * If we are working on partial mode, then we will split it in 2 halves
    318          */
    319         if ($this->preordersMode == 'partial') {
     311        // If we are working on partial mode, then we will split it in 2 halves
     312        if ('partial' === $this->preordersMode) {
    320313            return 2;
    321         /*
    322          * Otherwise we will have to split it by the amount of orders that we have
    323          */
    324         } elseif ($this->preordersMode == 'individual') {
    325             return 1+count($this->getPreorderedProducts($order));
    326         } else {
    327             return 1;
    328         }
     314            // Otherwise we will have to split it by the amount of orders that we have
     315        }
     316        if ('individual' === $this->preordersMode) {
     317            return 1 + \count($this->getPreorderedProducts($order));
     318        }
     319
     320        return 1;
    329321    }
    330322
     
    350342    {
    351343        return array_filter($fields, function ($key) use ($prefix) {
    352             return strpos($key, $prefix) === 0;
     344            return 0 === strpos($key, $prefix);
    353345        }, ARRAY_FILTER_USE_KEY);
    354346    }
  • pre-orders-for-woocommerce/trunk/src/Notices.php

    r2281061 r2290193  
    2828
    2929            if($availableFrom > $now && $diff > 0) {
    30                 echo '<br><small style="color:red"> '.sprintf(__("Note: this item will be available for shipping in %s days</small>",'preorders'),$diff).'</small>';
     30                echo '<br/><small style="color:red"> '.sprintf(__("Note: this item will be available for shipping in %s days</small>",'preorders'),$diff).'</small>';
    3131            }
    3232        }
  • pre-orders-for-woocommerce/trunk/src/Tabs.php

    r2281061 r2290193  
    5959
    6060        if ($is_pre_order_variation == 'yes') {
    61             $pre_order_date_value = sanitize_text_field($_POST['_pre_order_date_' . $post_id]);
    62             $product->update_meta_data('_pre_order_date', $pre_order_date_value);
     61            $pre_order_date_value = esc_html($_POST['_pre_order_date_' . $post_id]);
     62            $product->update_meta_data('_pre_order_date', esc_attr($pre_order_date_value));
    6363        }
    6464
     
    100100
    101101        if ($is_pre_order_variation == 'yes') {
    102             $pre_order_date_value = sanitize_text_field($_POST['_pre_order_date']);
    103             $product->update_meta_data('_pre_order_date', $pre_order_date_value);
     102            $pre_order_date_value = esc_html($_POST['_pre_order_date']);
     103            $product->update_meta_data('_pre_order_date', esc_attr($pre_order_date_value));
    104104        }
    105105
Note: See TracChangeset for help on using the changeset viewer.