| 1 |
/** |
| 2 |
* Merchant Pre Orders. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
'use strict'; |
| 7 |
|
| 8 |
var merchant = merchant || {}; |
| 9 |
merchant.modules = merchant.modules || {}; |
| 10 |
(function ($) { |
| 11 |
merchant.modules.preOrders = { |
| 12 |
init: function init() { |
| 13 |
var self = this; |
| 14 |
var cachedAddToCartText; |
| 15 |
$(document).on('show_variation', '.variations_form', function (event, variation) { |
| 16 |
var $product = $(this).closest('.product'); |
| 17 |
var $button = $product.find('.single_add_to_cart_button:not(.merchant_buy_now_button)'); |
| 18 |
var $form = $product.find('.variations_form'); |
| 19 |
var $dateTxt = $product.find('.merchant-pre-orders-date'); |
| 20 |
if (!cachedAddToCartText) { |
| 21 |
cachedAddToCartText = $button.html(); |
| 22 |
} |
| 23 |
if ($dateTxt.length) { |
| 24 |
$dateTxt.remove(); |
| 25 |
} |
| 26 |
$product.removeClass('merchant-pre-ordered-product'); |
| 27 |
if (variation.is_pre_order === true) { |
| 28 |
if (variation.is_pre_order_date) { |
| 29 |
$product.addClass('merchant-pre-ordered-product'); |
| 30 |
if (variation.pre_order_placement === 'before') { |
| 31 |
$product.find('.variations_form.cart').before('<div class="merchant-pre-orders-date">' + variation.is_pre_order_date + '</div>'); |
| 32 |
} else if (variation.pre_order_placement === 'after') { |
| 33 |
$product.find('.variations_form.cart').after('<div class="merchant-pre-orders-date">' + variation.is_pre_order_date + '</div>'); |
| 34 |
} |
| 35 |
} |
| 36 |
$button.html(window.merchant.setting.pre_orders_add_button_title); |
| 37 |
} else { |
| 38 |
$button.html(cachedAddToCartText); |
| 39 |
} |
| 40 |
}); |
| 41 |
$(document).on('click.wc-variation-form', '.reset_variations', function () { |
| 42 |
var $product = $(this).closest('.product'); |
| 43 |
var $dateTxt = $product.find('.merchant-pre-orders-date'); |
| 44 |
if ($dateTxt.length) { |
| 45 |
$dateTxt.remove(); |
| 46 |
} |
| 47 |
$product.removeClass('merchant-pre-ordered-product'); |
| 48 |
$product.find('.single_add_to_cart_button:not(.merchant_buy_now_button)').html(cachedAddToCartText); |
| 49 |
}); |
| 50 |
} |
| 51 |
}; |
| 52 |
merchant.modules.preOrders.init(); |
| 53 |
})(jQuery); |