first commit
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Start Checking subscribed customer and alert about stock
|
||||
*
|
||||
*/
|
||||
class WOO_Product_Stock_Alert_Action {
|
||||
|
||||
public function __construct() {
|
||||
// Call to cron action
|
||||
add_action('dc_start_stock_alert', array($this, 'stock_alert_action'));
|
||||
}
|
||||
|
||||
function stock_alert_action() {
|
||||
global $WC;
|
||||
$all_products = array();
|
||||
$all_products = get_posts(
|
||||
array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => -1
|
||||
)
|
||||
);
|
||||
$all_product_ids = array();
|
||||
if (!empty($all_products) && is_array($all_products)) {
|
||||
foreach ($all_products as $products_each) {
|
||||
$child_ids = $product_obj = array();
|
||||
$product_obj = wc_get_product($products_each->ID);
|
||||
if ($product_obj && $product_obj->is_type('variable')) {
|
||||
if ($product_obj->has_child()) {
|
||||
$child_ids = $product_obj->get_children();
|
||||
if (isset($child_ids) && !empty($child_ids)) {
|
||||
foreach ($child_ids as $child_id) {
|
||||
$all_product_ids[] = $child_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$all_product_ids[] = $products_each->ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$get_subscribed_user = array();
|
||||
if (!empty($all_product_ids) && is_array($all_product_ids)) {
|
||||
foreach ($all_product_ids as $product_id) {
|
||||
$subscribers_email = get_product_subscribers_email($product_id);
|
||||
if ($subscribers_email && !empty($subscribers_email)) {
|
||||
$get_subscribed_user[$product_id] = $subscribers_email;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($get_subscribed_user) && is_array($get_subscribed_user)) {
|
||||
foreach ($get_subscribed_user as $p_id => $subscriber) {
|
||||
$product = wc_get_product($p_id);
|
||||
$product_availability_stock = $product->get_stock_quantity();
|
||||
$manage_stock = $product->get_manage_stock();
|
||||
$managing_stock = $product->managing_stock();
|
||||
$stock_status = $product->get_stock_status();
|
||||
if ( $managing_stock ) {
|
||||
if ($product->backorders_allowed() && get_mvx_product_alert_plugin_settings('is_enable_backorders')) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($subscriber as $post_id => $to) {
|
||||
$email->trigger($to, $p_id);
|
||||
|
||||
update_subscriber($post_id, 'woo_mailsent');
|
||||
delete_post_meta($p_id, 'no_of_subscribers');
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($product_availability_stock > (int) get_option('woocommerce_notify_no_stock_amount')) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($subscriber as $post_id => $to) {
|
||||
$email->trigger($to, $p_id);
|
||||
|
||||
update_subscriber($post_id, 'woo_mailsent');
|
||||
delete_post_meta($p_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($stock_status == 'onbackorder' && get_mvx_product_alert_plugin_settings('is_enable_backorders')) {
|
||||
if ($stock_status != 'outofstock' || $product_availability_stock > (int) get_option('woocommerce_notify_no_stock_amount')) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($subscriber as $post_id => $to) {
|
||||
$email->trigger($to, $p_id);
|
||||
|
||||
update_subscriber($post_id, 'woo_mailsent');
|
||||
delete_post_meta($p_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
} elseif ($stock_status == 'instock' ) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($subscriber as $post_id => $to) {
|
||||
$email->trigger($to, $p_id);
|
||||
update_subscriber($post_id, 'woo_mailsent');
|
||||
delete_post_meta($p_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
<?php
|
||||
|
||||
class WOO_Product_Stock_Alert_Admin {
|
||||
public $settings;
|
||||
|
||||
public function __construct() {
|
||||
//admin script and style
|
||||
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_script'));
|
||||
$this->load_class('settings');
|
||||
$this->settings = new WOO_Product_Stock_Alert_Settings();
|
||||
add_action('admin_menu', array($this, 'add_export_page'), 100);
|
||||
|
||||
if (get_mvx_product_alert_plugin_settings('is_enable')) {
|
||||
// create custom column
|
||||
add_action('manage_edit-product_columns', array($this, 'custom_column'));
|
||||
// manage stock alert column
|
||||
add_action('manage_product_posts_custom_column', array($this, 'manage_custom_column'), 10, 2);
|
||||
// manage interest column
|
||||
add_filter('manage_edit-product_sortable_columns', array($this, 'manage_interest_column_sorting'));
|
||||
add_filter('request', array($this, 'manage_interest_column_orderby'));
|
||||
|
||||
// show number of subscribers for individual product
|
||||
add_action('woocommerce_product_options_inventory_product_data', array($this, 'product_subscriber_details'));
|
||||
add_action('woocommerce_product_after_variable_attributes', array($this, 'manage_variation_custom_column'), 10, 3);
|
||||
|
||||
// check product stock status
|
||||
add_action('save_post', array($this, 'check_product_stock_status'), 5, 2);
|
||||
|
||||
// bulk action to remove subscribers
|
||||
add_filter('bulk_actions-edit-product', array($this, 'register_subscribers_bulk_actions'));
|
||||
add_filter('handle_bulk_actions-edit-product', array($this, 'subscribers_bulk_action_handler'), 10, 3);
|
||||
add_action('admin_notices', array($this, 'subscribers_bulk_action_admin_notice'));
|
||||
add_action( 'admin_print_styles-plugins.php', array( $this, 'admin_plugin_page_style' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function load_class($class_name = '') {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
if ('' != $class_name) {
|
||||
require_once ($WOO_Product_Stock_Alert->plugin_path . '/admin/class-' . esc_attr($WOO_Product_Stock_Alert->token) . '-' . esc_attr($class_name) . '.php');
|
||||
} // End If Statement
|
||||
}
|
||||
|
||||
function register_subscribers_bulk_actions($bulk_actions) {
|
||||
$bulk_actions['remove_subscribers'] = __('Remove Subscribers', 'woocommerce-product-stock-alert');
|
||||
return $bulk_actions;
|
||||
}
|
||||
|
||||
function subscribers_bulk_action_handler($redirect_to, $doaction, $post_ids) {
|
||||
if ($doaction !== 'remove_subscribers') {
|
||||
return $redirect_to;
|
||||
}
|
||||
foreach ($post_ids as $post_id) {
|
||||
$product = wc_get_product($post_id);
|
||||
if($product && $product->is_type('variable')) {
|
||||
if ($product->has_child()) {
|
||||
$child_ids = $product->get_children();
|
||||
if (isset($child_ids) && !empty($child_ids)) {
|
||||
foreach ($child_ids as $child_id) {
|
||||
$subscribers_email = get_product_subscribers_email($child_id);
|
||||
if ($subscribers_email && !empty($subscribers_email)) {
|
||||
foreach ($subscribers_email as $alert_id => $to) {
|
||||
update_subscriber($alert_id, 'woo_unsubscribed');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$subscribers_email = get_product_subscribers_email($post_id);
|
||||
if ($subscribers_email && !empty($subscribers_email)) {
|
||||
foreach ($subscribers_email as $alert_id => $to) {
|
||||
update_subscriber($alert_id, 'woo_unsubscribed');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$redirect_to = add_query_arg('bulk_remove_subscribers', count($post_ids), $redirect_to);
|
||||
return $redirect_to;
|
||||
}
|
||||
|
||||
function subscribers_bulk_action_admin_notice() {
|
||||
if (!empty($_REQUEST['bulk_remove_subscribers'])) {
|
||||
$bulk_remove_count = intval($_REQUEST['bulk_remove_subscribers']);
|
||||
printf('<div id="message" class="updated fade"><p>' .
|
||||
_n('Removed subscribers from %s product.', 'Removed subscribers from %s products.', $bulk_remove_count, 'woocommerce-product-stock-alert'
|
||||
) . '</p></div>', $bulk_remove_count);
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_plugin_page_style() {
|
||||
?>
|
||||
<style>
|
||||
a.stock-alert-pro-plugin{
|
||||
font-weight: 700;
|
||||
background: linear-gradient(110deg, rgb(63, 20, 115) 0%, 25%, rgb(175 59 116) 50%, 75%, rgb(219 75 84) 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
a.stock-alert-pro-plugin:hover {
|
||||
background: #3f1473;
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Scripts
|
||||
*/
|
||||
public function enqueue_admin_script() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
$product_selection = '';
|
||||
$product_query = new WP_Query(array('posts_per_page' => -1, 'post_type' => 'product', 'post_status' => 'publish'));
|
||||
if ($product_query->get_posts()) {
|
||||
$product_selection = mvx_convert_select_structure($product_query->get_posts(), '', true);
|
||||
}
|
||||
$columns_subscriber = apply_filters('woo_stock_alert_subscribers_list_headers', array(
|
||||
array(
|
||||
'name' => __('Date', 'woocommerce-product-stock-alert'),
|
||||
'selector' => '',
|
||||
'sortable' => false,
|
||||
'selector_choice' => "date",
|
||||
),
|
||||
array(
|
||||
'name' => __('Product', 'woocommerce-product-stock-alert'),
|
||||
'selector' => '',
|
||||
'sortable' => false,
|
||||
'selector_choice' => "product",
|
||||
),
|
||||
array(
|
||||
'name' => __('Email', 'woocommerce-product-stock-alert'),
|
||||
'selector' => '',
|
||||
'sortable' => false,
|
||||
'selector_choice' => "email",
|
||||
),
|
||||
array(
|
||||
'name' => __('Registred User', 'woocommerce-product-stock-alert'),
|
||||
'selector' => '',
|
||||
'sortable' => false,
|
||||
'selector_choice' => "reg_user",
|
||||
),
|
||||
array(
|
||||
'name' => __('Status', 'woocommerce-product-stock-alert'),
|
||||
'selector' => '',
|
||||
'sortable' => false,
|
||||
'selector_choice' => "status",
|
||||
)
|
||||
));
|
||||
$subscription_statuses = array(
|
||||
'subscribe' => __('Subscribe', 'woocommerce-product-stock-alert'),
|
||||
'unsubscribe' => __('Unsubscribe', 'woocommerce-product-stock-alert'),
|
||||
'mail_sent' => __('Mail Sent', 'woocommerce-product-stock-alert'),
|
||||
'trash' => __('Trash', 'woocommerce-product-stock-alert'),
|
||||
);
|
||||
$subscription_status_list_action = mvx_convert_select_structure($subscription_statuses);
|
||||
$subscription_page_string = array(
|
||||
'all' => __('All', 'woocommerce-product-stock-alert'),
|
||||
'subscribe' => __('Subscribe', 'woocommerce-product-stock-alert'),
|
||||
'unsubscribe' => __('Unsubscribe', 'woocommerce-product-stock-alert'),
|
||||
'mail_sent' => __('Mail Sent', 'woocommerce-product-stock-alert'),
|
||||
'trash' => __('Trash', 'woocommerce-product-stock-alert'),
|
||||
'search' => __('Search by Email', 'woocommerce-product-stock-alert'),
|
||||
'show_product' => __('Products', 'woocommerce-product-stock-alert'),
|
||||
'product_select'=> $product_selection,
|
||||
);
|
||||
|
||||
if (get_current_screen()->id == 'toplevel_page_woo-stock-alert-setting') {
|
||||
wp_enqueue_script( 'mvx-stockalert-script', $WOO_Product_Stock_Alert->plugin_url . 'build/index.js', array( 'wp-element' ), $WOO_Product_Stock_Alert->version, true );
|
||||
wp_localize_script( 'mvx-stockalert-script', 'stockalertappLocalizer', apply_filters('stockalert_settings', [
|
||||
'apiUrl' => home_url( '/wp-json' ),
|
||||
'nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'banner_img' => $WOO_Product_Stock_Alert->plugin_url . 'assets/images/stock-alert-pro-banner.jpg',
|
||||
'pro_active' => apply_filters('woo_stock_alert_pro_active', 'free'),
|
||||
'columns_subscriber' => $columns_subscriber,
|
||||
'subscription_page_string' => $subscription_page_string,
|
||||
'download_csv' => __('Download CSV', 'woocommerce-product-stock-alert')
|
||||
] ) );
|
||||
wp_enqueue_style( 'mvx-stockalert-style', $WOO_Product_Stock_Alert->plugin_url . 'build/index.css' );
|
||||
wp_enqueue_style('mvx_admin_rsuite_css', $WOO_Product_Stock_Alert->plugin_url . 'assets/admin/css/rsuite-default' . '.min' . '.css', array(), $WOO_Product_Stock_Alert->version);
|
||||
}
|
||||
if (get_current_screen()->id == 'tools_page_woo-product-stock-alert-export-admin') {
|
||||
wp_enqueue_script('stock_alert_admin_js', $WOO_Product_Stock_Alert->plugin_url . 'assets/admin/js/admin'. $suffix .'.js', array('jquery'), $WOO_Product_Stock_Alert->version, true);
|
||||
wp_localize_script('stock_alert_admin_js', 'dc_params', array( 'ajaxurl' => 'admin-ajax.php' ));
|
||||
}
|
||||
wp_enqueue_style('stock_alert_product_admin_css', $WOO_Product_Stock_Alert->plugin_url . 'assets/admin/css/admin'. $suffix .'.css' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom column addition
|
||||
*/
|
||||
function custom_column($columns) {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
return array_merge($columns, array('product_subscriber' => __('Interested Person(s)', 'woocommerce-product-stock-alert')));
|
||||
}
|
||||
|
||||
function manage_interest_column_sorting($columns) {
|
||||
$columns['product_subscriber'] = 'product_subscriber';
|
||||
return $columns;
|
||||
}
|
||||
|
||||
function manage_interest_column_orderby($vars) {
|
||||
|
||||
if (isset($vars['orderby']) && 'product_subscriber' == $vars['orderby']) {
|
||||
$vars = array_merge($vars, array(
|
||||
'meta_key' => 'no_of_subscribers',
|
||||
'orderby' => 'meta_value'
|
||||
));
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add options page
|
||||
*/
|
||||
public function add_export_page() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
|
||||
add_submenu_page(
|
||||
'tools.php', __('WC Stock Alert Export', 'woocommerce-product-stock-alert'), __('WC Stock Alert Export', 'woocommerce-product-stock-alert'), 'manage_options', 'woo-product-stock-alert-export-admin', array($this, 'create_woo_product_stock_alert_export')
|
||||
);
|
||||
}
|
||||
|
||||
function create_woo_product_stock_alert_export() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
new WOO_Product_Stock_Alert_Export();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage custom column for Stock Alert
|
||||
*/
|
||||
function manage_custom_column($column_name, $post_id) {
|
||||
$no_of_subscriber = 0;
|
||||
$product_subscriber = $child_ids = $product_obj = array();
|
||||
switch ($column_name) {
|
||||
case 'product_subscriber' :
|
||||
$product_obj = wc_get_product($post_id);
|
||||
if (!$product_obj->is_type('grouped')) {
|
||||
if ($product_obj->is_type('variable')) {
|
||||
$child_ids = $product_obj->get_children();
|
||||
if (isset($child_ids) && !empty($child_ids)) {
|
||||
foreach ($child_ids as $child_id) {
|
||||
if (mvx_is_product_outofstock($child_id, 'variation')) {
|
||||
$no_of_subscriber += get_no_subscribed_persons($child_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
echo $no_of_subscriber;
|
||||
} else {
|
||||
$no_of_subscriber += get_no_subscribed_persons($product_obj->get_id());
|
||||
echo $no_of_subscriber;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stock Alert news on Product edit page (simple)
|
||||
*/
|
||||
function product_subscriber_details() {
|
||||
global $post, $WOO_Product_Stock_Alert;
|
||||
$no_of_subscriber = 0;
|
||||
$product_obj = wc_get_product($post->ID);
|
||||
if (!$product_obj->is_type('variable')) {
|
||||
if (mvx_is_product_outofstock($post->ID)) {
|
||||
$no_of_subscriber = get_no_subscribed_persons($post->ID);
|
||||
if (!empty($no_of_subscriber) && $no_of_subscriber > 0) {
|
||||
?>
|
||||
<p class="form-field _stock_field">
|
||||
<label class=""><?php _e('Number of Interested Person(s)', 'woocommerce-product-stock-alert'); ?></label>
|
||||
<span class="no_subscriber"><?php echo $no_of_subscriber; ?></span>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stock Alert news on Product edit page (variable)
|
||||
*/
|
||||
function manage_variation_custom_column($loop, $variation_data, $variation) {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
if (mvx_is_product_outofstock($variation->ID, 'variation')) {
|
||||
$product_subscriber = get_no_subscribed_persons($variation->ID);
|
||||
if (!empty($product_subscriber) && $product_subscriber >0) {
|
||||
?>
|
||||
<p class="form-row form-row-full interested_person">
|
||||
<label class="stock_label"><?php echo _e('Number of Interested Person(s) : ', 'woocommerce-product-stock-alert'); ?></label>
|
||||
<div class="variation_no_subscriber"><?php echo $product_subscriber; ?></div>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alert on Product Stock Update
|
||||
*
|
||||
*/
|
||||
function check_product_stock_status($post_id, $post) {
|
||||
if ($post->post_type == 'product') {
|
||||
$product_subscriber = array();
|
||||
$product_obj = array();
|
||||
$product_obj = wc_get_product($post_id);
|
||||
if ($product_obj && $product_obj->is_type('variable')) {
|
||||
if ($product_obj->has_child()) {
|
||||
$child_ids = $product_obj->get_children();
|
||||
if (isset($child_ids) && !empty($child_ids)) {
|
||||
foreach ($child_ids as $child_id) {
|
||||
$child_obj = new WC_Product_Variation($child_id);
|
||||
$product_subscriber = get_product_subscribers_email( $child_id );
|
||||
if (isset($product_subscriber) && !empty($product_subscriber)) {
|
||||
$product_availability_stock = $child_obj->get_stock_quantity();
|
||||
$manage_stock = $child_obj->get_manage_stock();
|
||||
$stock_status = $child_obj->get_stock_status();
|
||||
if (isset($product_availability_stock) && $manage_stock) {
|
||||
if ($product_availability_stock > (int) get_option('woocommerce_notify_no_stock_amount')) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($product_subscriber as $subscribe_id => $to) {
|
||||
$email->trigger($to, $child_id);
|
||||
update_subscriber($subscribe_id, 'woo_mailsent');
|
||||
delete_post_meta($child_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
} elseif ($stock_status == 'instock' ) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($product_subscriber as $subscribe_id => $to) {
|
||||
$email->trigger($to, $child_id);
|
||||
update_subscriber($subscribe_id, 'woo_mailsent');
|
||||
delete_post_meta($child_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$product_subscriber = get_product_subscribers_email( $post_id );
|
||||
if (isset($product_subscriber) && !empty($product_subscriber)) {
|
||||
$product_availability_stock = $product_obj->get_stock_quantity();
|
||||
$manage_stock = $product_obj->get_manage_stock();
|
||||
$stock_status = $product_obj->get_stock_status();
|
||||
if (isset($product_availability_stock) && $manage_stock) {
|
||||
if ($product_availability_stock > (int) get_option('woocommerce_notify_no_stock_amount')) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($product_subscriber as $subscribe_id => $to) {
|
||||
$email->trigger($to, $post_id);
|
||||
update_subscriber($subscribe_id, 'woo_mailsent');
|
||||
delete_post_meta($post_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
} elseif ($stock_status == 'instock' ) {
|
||||
$email = WC()->mailer()->emails['WC_Email_Stock_Alert'];
|
||||
foreach ($product_subscriber as $subscribe_id => $to) {
|
||||
$email->trigger($to, $post_id);
|
||||
update_subscriber($subscribe_id, 'woo_mailsent');
|
||||
delete_post_meta($post_id, 'no_of_subscribers');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
class WOO_Product_Stock_Alert_Ajax {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
// Save customer email in database
|
||||
add_action( 'wp_ajax_alert_ajax', array(&$this, 'stock_alert_function') );
|
||||
add_action( 'wp_ajax_nopriv_alert_ajax', array(&$this, 'stock_alert_function') );
|
||||
|
||||
// Delete unsubscribed users
|
||||
add_action( 'wp_ajax_unsubscribe_button', array($this, 'unsubscribe_users') );
|
||||
add_action( 'wp_ajax_nopriv_unsubscribe_button', array($this, 'unsubscribe_users') );
|
||||
// Export data
|
||||
add_action( 'wp_ajax_export_subscribers', array($this, 'export_stock_alert_data') );
|
||||
|
||||
//add fields for variation product shortcode
|
||||
add_action( 'wp_ajax_nopriv_get_variation_box_ajax', array( $this, 'get_variation_box_ajax') );
|
||||
add_action('wp_ajax_get_variation_box_ajax', array( $this, 'get_variation_box_ajax') );
|
||||
|
||||
//recaptcha version-3 validate
|
||||
add_action( 'wp_ajax_recaptcha_validate_ajax', array($this, 'recaptcha_validate_ajax') );
|
||||
add_action( 'wp_ajax_nopriv_recaptcha_validate_ajax', array($this, 'recaptcha_validate_ajax') );
|
||||
}
|
||||
|
||||
function recaptcha_validate_ajax() {
|
||||
$recaptcha_secret = isset($_POST['captcha_secret']) ? $_POST['captcha_secret'] : '';
|
||||
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
$recaptcha_response = isset($_POST['captcha_response']) ? $_POST['captcha_response'] : '';
|
||||
|
||||
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
|
||||
$recaptcha = json_decode($recaptcha);
|
||||
if (!$recaptcha->success || $recaptcha->score < 0.5) {
|
||||
echo 0;
|
||||
} else {
|
||||
echo 1;
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
function export_stock_alert_data() {
|
||||
$headers_str = '';
|
||||
$headers_arr = $all_products = $all_products = $get_subscribed_user = $stock_alert_export_datas = $subscribers_list =array();
|
||||
$file_name = 'list_subscribers.csv';
|
||||
|
||||
// Set page headers to force download of CSV
|
||||
header("Content-type: text/x-csv");
|
||||
header("Content-Disposition: File Transfar");
|
||||
header("Content-Disposition: attachment;filename={$file_name}");
|
||||
|
||||
// Set CSV headers
|
||||
$headers = array(
|
||||
'product_id',
|
||||
'product_name',
|
||||
'product_sku',
|
||||
'product_type',
|
||||
'subscribers'
|
||||
);
|
||||
|
||||
|
||||
foreach($headers as $header) {
|
||||
$headers_arr[] = '"' . $header . '"';
|
||||
}
|
||||
$headers_str = implode(',', $headers_arr);
|
||||
|
||||
$all_products = get_posts(
|
||||
array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => -1
|
||||
)
|
||||
);
|
||||
|
||||
if( !empty($all_products) && is_array($all_products) ) {
|
||||
foreach( $all_products as $products_each ) {
|
||||
$child_ids = $product_obj = array();
|
||||
$product_obj = wc_get_product( $products_each->ID );
|
||||
if( $product_obj->is_type('variable') ) {
|
||||
if( $product_obj->has_child() ) {
|
||||
$child_ids = $product_obj->get_children();
|
||||
if( isset($child_ids) && !empty($child_ids) ) {
|
||||
foreach( $child_ids as $child_id ) {
|
||||
$all_product_ids[] = $child_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$all_product_ids[] = $products_each->ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !empty($all_product_ids) && is_array($all_product_ids) ) {
|
||||
foreach( $all_product_ids as $product_id ) {
|
||||
$subscribers = get_product_subscribers_email($product_id);
|
||||
if ($subscribers && !empty($subscribers) ) {
|
||||
$get_subscribed_user[$product_id] = $subscribers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $get_subscribed_user ) && !empty( $get_subscribed_user ) ) {
|
||||
foreach ($get_subscribed_user as $pro_id => $value) {
|
||||
$subscribers_list = implode(',',$value);
|
||||
$product = wc_get_product($pro_id);
|
||||
$stock_alert_export_datas[] = array(
|
||||
'"'.$pro_id.'"',
|
||||
'"'.$product->get_name().'"',
|
||||
'"'.$product->get_sku().'"',
|
||||
'"'.$product->get_type().'"',
|
||||
'"'.$subscribers_list.'"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
echo $headers_str;
|
||||
if( isset($stock_alert_export_datas) && !empty($stock_alert_export_datas) ) {
|
||||
foreach( $stock_alert_export_datas as $stock_alert_export_data ) {
|
||||
echo "\r\n";
|
||||
echo implode(",", $stock_alert_export_data);
|
||||
}
|
||||
}
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
function unsubscribe_users() {
|
||||
$customer_email = isset($_POST['customer_email']) ? sanitize_email($_POST['customer_email']) : '';
|
||||
$product_id = isset($_POST['product_id']) ? (int)$_POST['product_id'] : '';
|
||||
$variation_id = isset($_POST['var_id']) ? (int)$_POST['var_id'] : 0;
|
||||
$current_subscriber = array();
|
||||
$success = 'false';
|
||||
if ($product_id && !empty($product_id) && !empty($customer_email)) {
|
||||
$product = wc_get_product($product_id);
|
||||
if ($product && $product->is_type( 'variable' ) && $variation_id > 0) {
|
||||
$success = customer_stock_alert_unsubscribe($variation_id, $customer_email);
|
||||
} else {
|
||||
$success = customer_stock_alert_unsubscribe($product_id, $customer_email);
|
||||
}
|
||||
}
|
||||
echo $success;
|
||||
die();
|
||||
}
|
||||
|
||||
function stock_alert_function() {
|
||||
$customer_email = isset($_POST['email']) ? sanitize_email($_POST['email']) : '';
|
||||
$product_id = isset($_POST['product_id']) ? (int)$_POST['product_id'] : '';
|
||||
$variation_id = isset($_POST['variation_id']) ? (int)$_POST['variation_id'] : 0;
|
||||
$status = '';
|
||||
if ($product_id && !empty($product_id) && !empty($customer_email)) {
|
||||
$product = wc_get_product($product_id);
|
||||
if ($product && $product->is_type( 'variable' ) && $variation_id > 0) {
|
||||
$status = customer_stock_alert_insert($variation_id, $customer_email);
|
||||
} else {
|
||||
$status = customer_stock_alert_insert($product_id, $customer_email);
|
||||
}
|
||||
}
|
||||
echo $status;
|
||||
die();
|
||||
}
|
||||
|
||||
function get_variation_box_ajax(){
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$product_id = (int)$_POST['product_id'];
|
||||
$child_id = (int)$_POST['variation_id'];
|
||||
$product = wc_get_product( $product_id );
|
||||
$display_stock_alert_form = false;
|
||||
|
||||
if( $child_id && !empty($child_id) ) {
|
||||
$child_obj = new WC_Product_Variation($child_id);
|
||||
$stock_quantity = $child_obj->get_stock_quantity();
|
||||
$managing_stock = $child_obj->managing_stock();
|
||||
$is_in_stock = $child_obj->is_in_stock();
|
||||
$is_on_backorder = $child_obj->is_on_backorder( 1 );
|
||||
|
||||
if ( ! $is_in_stock ) {
|
||||
$display_stock_alert_form = true;
|
||||
} elseif ( $managing_stock && $is_on_backorder && get_mvx_product_alert_plugin_settings('is_enable_backorders') ) {
|
||||
$display_stock_alert_form = true;
|
||||
} elseif ( $managing_stock ) {
|
||||
if(get_option('woocommerce_notify_no_stock_amount')){
|
||||
if($stock_quantity <= (int) get_option('woocommerce_notify_no_stock_amount') && get_mvx_product_alert_plugin_settings('is_enable_backorders')){
|
||||
$display_stock_alert_form = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($display_stock_alert_form) {
|
||||
echo $WOO_Product_Stock_Alert->frontend->html_subscribe_form($product, $child_obj);
|
||||
}
|
||||
}
|
||||
die();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class WOO_Product_Stock_Alert_Export {
|
||||
|
||||
public function __construct() {
|
||||
$this->export_stock_alert_data();
|
||||
}
|
||||
|
||||
function export_stock_alert_data() {
|
||||
global $WOO_Product_Stock_Alert; ?>
|
||||
<div class="wrap">
|
||||
<h1><?php _e('WC Stock Alert Export', 'woocommerce-product-stock-alert') ?></h1>
|
||||
<p><?php _e('When you click the button below, this will export all out of stock products with subscribers email.', 'woocommerce-product-stock-alert') ?></p>
|
||||
<button class="wc_stock_alert_export_data button-primary"><?php _e('Export CSV', 'woocommerce-product-stock-alert') ?></button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
|
||||
class WOO_Product_Stock_Alert_Frontend {
|
||||
|
||||
public function __construct() {
|
||||
//enqueue scripts
|
||||
add_action('wp_enqueue_scripts', array(&$this, 'frontend_scripts'));
|
||||
//enqueue styles
|
||||
add_action('wp_enqueue_scripts', array(&$this, 'frontend_styles'));
|
||||
|
||||
if (get_mvx_product_alert_plugin_settings('is_enable')) {
|
||||
add_action( 'woocommerce_simple_add_to_cart', array( $this, 'display_in_simple_product' ), 31 );
|
||||
add_action( 'woocommerce_bundle_add_to_cart', array( $this, 'display_in_simple_product' ), 31 );
|
||||
add_action('woocommerce_subscription_add_to_cart', array($this, 'display_in_simple_product'), 31);
|
||||
add_action( 'woocommerce_woosb_add_to_cart', array( $this, 'display_in_simple_product' ), 31 );
|
||||
add_action( 'woocommerce_after_variations_form', array( $this, 'display_in_no_variation_product' ) );
|
||||
add_filter( 'woocommerce_available_variation', array( $this, 'display_in_variation' ), 10, 3 );
|
||||
// Some theme variation disabled by default if it is out of stock so for that workaround solution.
|
||||
add_filter( 'woocommerce_variation_is_active', array( $this, 'enable_disabled_variation_dropdown' ), 100, 2 );
|
||||
//support for grouped products
|
||||
add_filter('woocommerce_grouped_product_list_column_price', array($this, 'display_in_grouped_product'), 10, 2);
|
||||
// Hover style
|
||||
add_action('wp_head', array($this, 'frontend_style'));
|
||||
}
|
||||
}
|
||||
|
||||
function frontend_scripts() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$frontend_script_path = $WOO_Product_Stock_Alert->plugin_url . 'assets/frontend/js/';
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '';
|
||||
$stock_interest = $alert_text_html = $button_html = $button_css = '';
|
||||
$settings_array = get_woo_form_settings_array();
|
||||
|
||||
if (!empty($settings_array['alert_text'])) {
|
||||
$alert_text_html = '<h5 style="color:' . $settings_array['alert_text_color'] . '" class="subscribe_for_interest_text">' . $settings_array['alert_text'] . '</h5>';
|
||||
} else {
|
||||
$alert_text_html = '<h5 class="subscribe_for_interest_text">' . $settings_array['alert_text'] . '</h5>';
|
||||
}
|
||||
|
||||
if (!empty($settings_array['button_background_color']))
|
||||
$button_css .= "background:" . $settings_array['button_background_color'] . "; ";
|
||||
if (!empty($settings_array['button_text_color']))
|
||||
$button_css .= "color:" . $settings_array['button_text_color'] . "; ";
|
||||
if (!empty($settings_array['button_border_color']))
|
||||
$button_css .= "border: 1px solid " . $settings_array['button_border_color'] . "; ";
|
||||
if (!empty($settings_array['button_font_size']))
|
||||
$button_css .= "font-size:" . $settings_array['button_font_size'] . "; ";
|
||||
|
||||
|
||||
if (!empty($button_css)) {
|
||||
$button_html = '<button style="' . $button_css .'" class="stock_alert_button alert_button_hover" name="alert_button">' . $settings_array['button_text'] . '</button>';
|
||||
$unsubscribe_button_html = '<button class="unsubscribe_button" style="' . $button_css .'">' . $settings_array['unsubscribe_button_text'] . '</button>';
|
||||
} else {
|
||||
$button_html = '<button class="stock_alert_button" name="alert_button">' . $settings_array['button_text'] . '</button>';
|
||||
$unsubscribe_button_html = '<button class="unsubscribe_button">' . $settings_array['unsubscribe_button_text'] . '</button>';
|
||||
}
|
||||
|
||||
if (function_exists('is_product')) {
|
||||
if (is_product()) {
|
||||
// Enqueue your frontend javascript from here
|
||||
wp_enqueue_script('stock_alert_frontend_js', $frontend_script_path . 'frontend' . $suffix . '.js', array('jquery'), $WOO_Product_Stock_Alert->version, true);
|
||||
|
||||
wp_localize_script('stock_alert_frontend_js', 'woo_stock_alert_script_data', array('ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
||||
'alert_fields' => woo_stock_alert_fileds(),
|
||||
'additional_fields' => apply_filters('woocommerce_product_stock_alert_form_additional_fields', []),
|
||||
'alert_text_html' => $alert_text_html,
|
||||
'button_html' => $button_html,
|
||||
'alert_success' => $settings_array['alert_success'],
|
||||
'alert_email_exist' => $settings_array['alert_email_exist'],
|
||||
'valid_email' => $settings_array['valid_email'],
|
||||
'ban_email_domin' => $settings_array['ban_email_domin'],
|
||||
'ban_email_address' => $settings_array['ban_email_address'],
|
||||
'double_opt_in_success' => $settings_array['double_opt_in_success'],
|
||||
'processing' => __('Processing...', 'woocommerce-product-stock-alert'),
|
||||
'error_occurs' => __('Some error occurs', 'woocommerce-product-stock-alert'),
|
||||
'try_again' => __('Please try again.', 'woocommerce-product-stock-alert'),
|
||||
'unsubscribe_button' => $unsubscribe_button_html,
|
||||
'alert_unsubscribe_message' => $settings_array['alert_unsubscribe_message'],
|
||||
'recaptcha_enabled' => apply_filters('woo_stock_alert_recaptcha_enableed', false),
|
||||
'recaptcha_version' => apply_filters('woo_stock_alert_recaptcha_version', '')
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function frontend_styles() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$frontend_style_path = $WOO_Product_Stock_Alert->plugin_url . 'assets/frontend/css/';
|
||||
|
||||
if (function_exists('is_product')) {
|
||||
if (is_product()) {
|
||||
// Enqueue your frontend stylesheet from here
|
||||
wp_enqueue_style('stock_alert_frontend_css', $frontend_style_path . 'frontend.css', array(), $WOO_Product_Stock_Alert->version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function frontend_style() {
|
||||
$settings_array = get_woo_form_settings_array();
|
||||
$button_onhover_style = '';
|
||||
if (isset($settings_array['button_background_color_onhover']))
|
||||
$button_onhover_style .= !empty($settings_array['button_background_color_onhover']) ? 'background: ' . $settings_array['button_background_color_onhover'] . ' !important;' : '';
|
||||
if (isset($settings_array['button_text_color_onhover']))
|
||||
$button_onhover_style .= !empty($settings_array['button_text_color_onhover']) ? ' color: ' . $settings_array['button_text_color_onhover'] . ' !important;' : '';
|
||||
if (isset($settings_array['button_border_color_onhover']))
|
||||
$button_onhover_style .= !empty($settings_array['button_border_color_onhover']) ? 'border: 1px solid' . $settings_array['button_border_color_onhover'] . ' !important;' : '';
|
||||
if ($button_onhover_style) {
|
||||
echo '<style>
|
||||
button.alert_button_hover:hover, button.unsubscribe_button:hover {
|
||||
'. $button_onhover_style .'
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Request Stock Button for simple product
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public function display_in_simple_product() {
|
||||
global $product;
|
||||
echo _e( $this->display_subscribe_box( $product ) );
|
||||
}
|
||||
|
||||
public function display_in_grouped_product( $value, $child) {
|
||||
$value = $value . $this->display_subscribe_box($child, array());
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Reuest Stock Button in no variation product
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public function display_in_no_variation_product() {
|
||||
global $product;
|
||||
$product_type = $product->get_type();
|
||||
// Get Available variations?
|
||||
if ( 'variable' == $product_type ) {
|
||||
$get_variations = count( $product->get_children() ) <= apply_filters( 'woocommerce_ajax_variation_threshold', 30, $product );
|
||||
$get_variations = $get_variations ? $product->get_available_variations() : false;
|
||||
if ( ! $get_variations ) {
|
||||
echo _e( $this->display_subscribe_box( $product ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Subscribe from in shop page and single product page.
|
||||
*
|
||||
* @param object $product all product.
|
||||
* @param object $variation all Variabtion product.
|
||||
*
|
||||
* @return html $html
|
||||
*/
|
||||
public function display_subscribe_box( $product, $variation = [] ) {
|
||||
$get_option_backorder = get_mvx_product_alert_plugin_settings('is_enable_backorders');
|
||||
$visibility_backorder = isset( $get_option_backorder ) ? true : false;
|
||||
|
||||
if ( ! $variation && $this->is_stock_product( $product ) ) {
|
||||
return $this->html_subscribe_form( $product );
|
||||
} elseif ( $variation && $this->is_stock_product( $variation ) ) {
|
||||
return $this->html_subscribe_form( $product, $variation );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Subscribe form chacking.
|
||||
*
|
||||
* @param object $product
|
||||
*
|
||||
* @return boolen $flag
|
||||
*/
|
||||
public function is_stock_product( $product ) {
|
||||
$visibility_backorder = get_mvx_product_alert_plugin_settings('is_enable_backorders');
|
||||
$flag = false;
|
||||
if ($product) {
|
||||
if (!$product->managing_stock()) {
|
||||
$stock_status = $product->get_stock_status();
|
||||
if ($stock_status && $stock_status == 'outofstock') {
|
||||
$flag = true;
|
||||
} else if ($stock_status && $stock_status == 'onbackorder' && $visibility_backorder) {
|
||||
$flag = true;
|
||||
}
|
||||
} else {
|
||||
if ($product->backorders_allowed() && $visibility_backorder) {
|
||||
$flag = true;
|
||||
} else {
|
||||
if ($product->get_stock_quantity() < 1) {
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return apply_filters('woo_stock_alert_is_stock_product', $flag, $product);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display Subscribe from in shop page and single product page.
|
||||
*
|
||||
* @param object $product all Product.
|
||||
* @param object $variation Variabtion product.
|
||||
* @param string $html prev html button.
|
||||
* @param int $loopActive check loopActive.
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public function html_subscribe_form( $product, $variation = [] ) {
|
||||
$stock_notifier_random_code = bin2hex( random_bytes( 12 ) );
|
||||
$variation_class = '';
|
||||
if ( $variation ) {
|
||||
$variation_id = $variation->get_id();
|
||||
$interested_person = get_no_subscribed_persons($variation->get_id(), 'woo_subscribed');
|
||||
$variation_class = 'stock_notifier-subscribe-form-' . $variation_id;
|
||||
} else {
|
||||
$variation_id = 0;
|
||||
$interested_person = get_no_subscribed_persons($product->get_id(), 'woo_subscribed');
|
||||
}
|
||||
$stock_interest = $alert_text_html = $button_html = $button_css = '';
|
||||
$dc_settings = array();
|
||||
$alert_text = $button_text = $button_background_color = $button_border_color = $button_text_color = $unsubscribe_button_text = '';
|
||||
$alert_success = $alert_email_exist = $valid_email = $alert_unsubscribe_message = '';
|
||||
$settings_array = get_woo_form_settings_array();
|
||||
|
||||
if (!empty($settings_array['alert_text'])) {
|
||||
$alert_text_html = '<h5 style="color:' . $settings_array['alert_text_color'] . '" class="subscribe_for_interest_text">' . $settings_array['alert_text'] . '</h5>';
|
||||
} else {
|
||||
$alert_text_html = '<h5 class="subscribe_for_interest_text">' . $settings_array['alert_text'] . '</h5>';
|
||||
}
|
||||
|
||||
if (!empty($settings_array['button_background_color']))
|
||||
$button_css .= "background:" . $settings_array['button_background_color'] . ";";
|
||||
if (!empty($settings_array['button_text_color']))
|
||||
$button_css .= "color:" . $settings_array['button_text_color'] . ";";
|
||||
if (!empty($settings_array['button_border_color']))
|
||||
$button_css .= "border: 1px solid " . $settings_array['button_border_color'] . ";";
|
||||
if (!empty($settings_array['button_font_size']))
|
||||
$button_css .= "font-size:" . $settings_array['button_font_size'] . ";";
|
||||
|
||||
|
||||
if (!empty($button_css)) {
|
||||
$button_html = '<button style="' . $button_css .'" class="stock_alert_button alert_button_hover" name="alert_button">' . $settings_array['button_text'] . '</button>';
|
||||
$unsubscribe_button_html = '<button class="unsubscribe_button" style="' . $button_css .'">' . $settings_array['unsubscribe_button_text'] . '</button>';
|
||||
} else {
|
||||
$button_html = '<button class="stock_alert_button" name="alert_button">' . $settings_array['button_text'] . '</button>';
|
||||
$unsubscribe_button_html = '<button class="unsubscribe_button">' . $settings_array['unsubscribe_button_text'] . '</button>';
|
||||
}
|
||||
|
||||
$shown_interest_section = '';
|
||||
$shown_interest_text = $settings_array['shown_interest_text'];
|
||||
if (get_mvx_product_alert_plugin_settings('is_enable_no_interest') && $interested_person != 0) {
|
||||
if ($shown_interest_text) {
|
||||
$shown_interest_text = str_replace("%no_of_subscribed%", $interested_person, $shown_interest_text);
|
||||
$shown_interest_section = '<p>' . $shown_interest_text . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
wp_localize_script(
|
||||
'stock_alert_frontend_js', 'form_submission_text', array(
|
||||
'alert_text_html' => $alert_text_html,
|
||||
'button_html' => $button_html,
|
||||
'alert_success' => $settings_array['alert_success'],
|
||||
'alert_email_exist' => $settings_array['alert_email_exist'],
|
||||
'valid_email' => $settings_array['valid_email'],
|
||||
'ban_email_domin' => $settings_array['ban_email_domin'],
|
||||
'ban_email_address' => $settings_array['ban_email_address'],
|
||||
'double_opt_in_success' => $settings_array['double_opt_in_success'],
|
||||
'unsubscribe_button' => $unsubscribe_button_html,
|
||||
'alert_unsubscribe_message' => $settings_array['alert_unsubscribe_message'],
|
||||
'alert_fields' => woo_stock_alert_fileds(),
|
||||
'recaptcha_enabled' => apply_filters('woo_stock_alert_recaptcha_enableed', false),
|
||||
'recaptcha_version' => apply_filters('woo_stock_alert_recaptcha_version', '')
|
||||
));
|
||||
|
||||
$user_email = '';
|
||||
if (is_user_logged_in()) {
|
||||
$current_user = wp_get_current_user();
|
||||
$user_email = $current_user->data->user_email;
|
||||
}
|
||||
$alert_fields = woo_stock_alert_fileds();
|
||||
$stock_interest .= '
|
||||
<div id="stock_notifier_main_form" style="border-radius:10px;" class="stock_notifier-subscribe-form ' . esc_attr( $variation_class ) .'">
|
||||
' . $alert_text_html . '
|
||||
<div class="woo_fields_wrap"> ' . $alert_fields . '' . $button_html . '
|
||||
</div>
|
||||
<input type="hidden" class="current_product_id" value="' . $product->get_id() . '" />
|
||||
<input type="hidden" class="current_variation_id" value="' . $variation_id . '" />
|
||||
<input type="hidden" class="current_product_name" value="' . $product->get_title() . '" />
|
||||
' . $shown_interest_section . '
|
||||
</div>';
|
||||
return $stock_interest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display in variation product request stock button
|
||||
*
|
||||
* @param string $atts default attributes.
|
||||
* @param object $product all product.
|
||||
* @param object $variation variation product.
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public function display_in_variation( $atts, $product, $variation ) {
|
||||
$get_stock = $atts['availability_html'];
|
||||
$atts['availability_html'] = $get_stock . $this->display_subscribe_box( $product, $variation );
|
||||
return $atts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable disabled variation dropdown
|
||||
* @param int $active default 0.
|
||||
* @param array $variation variation product.
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public function enable_disabled_variation_dropdown( $active, $variation ) {
|
||||
$get_disabled_variation = get_option( 'stock_notifier_ignore_disabled_variation' );
|
||||
$ignore_disabled_variation = isset( $get_disabled_variation ) && '1' == $get_disabled_variation ? true : false;
|
||||
if ( ! $ignore_disabled_variation ) {
|
||||
$active = true;
|
||||
}
|
||||
return $active;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Start schedule after plugin activation
|
||||
*
|
||||
*/
|
||||
|
||||
class WOO_Product_Stock_Alert_Install {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
if (!get_option('dc_product_stock_alert_activate')) {
|
||||
if ($this->stock_alert_activate() == 'true') {
|
||||
update_option('dc_product_stock_alert_activate', 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (get_option( 'dc_product_stock_alert_installed' )) :
|
||||
$this->start_cron_job();
|
||||
endif;
|
||||
|
||||
if (!get_option('_is_updated_mvx_product_alert_settings')) {
|
||||
$this->mvx_stock_alert_older_settings_migration();
|
||||
}
|
||||
|
||||
if (!get_option('_is_updated_mvx_product_alert_database')) {
|
||||
$this->mvx_stock_alert_older_data_migration();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will start the cron job
|
||||
*/
|
||||
function start_cron_job() {
|
||||
wp_clear_scheduled_hook('dc_start_stock_alert');
|
||||
wp_schedule_event( time(), 'hourly', 'dc_start_stock_alert' );
|
||||
update_option( 'dc_product_stock_alert_cron_start', 1 );
|
||||
}
|
||||
|
||||
function stock_alert_activate() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$stock_alert_settings = array();
|
||||
$stock_alert_settings = array(
|
||||
'is_enable' => 'is_enable'
|
||||
);
|
||||
|
||||
if( !get_option('mvx_woo_stock_alert_general_tab_settings') ) {
|
||||
if( update_option( 'mvx_woo_stock_alert_general_tab_settings', $stock_alert_settings ) ) {
|
||||
return 'true';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will migrate older settings
|
||||
*/
|
||||
function mvx_stock_alert_older_settings_migration() {
|
||||
if (!get_option('_is_updated_mvx_product_alert_settings')) {
|
||||
$genaral_settings = $customization_settings = $submit_settings = [];
|
||||
if ( get_mvx_product_alert_old_plugin_settings('is_enable') && get_mvx_product_alert_old_plugin_settings('is_enable') == 'Enable' ) {
|
||||
$genaral_settings['is_enable'] = array('is_enable');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('is_enable_backorders') && get_mvx_product_alert_old_plugin_settings('is_enable_backorders') == 'Enable' ) {
|
||||
$genaral_settings['is_enable_backorders'] = array('is_enable_backorders');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('is_enable_no_interest') && get_mvx_product_alert_old_plugin_settings('is_enable_no_interest') == 'Enable' ) {
|
||||
$genaral_settings['is_enable_no_interest'] = array('is_enable_no_interest');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('shown_interest_text') ) {
|
||||
$genaral_settings['shown_interest_text'] = get_mvx_product_alert_old_plugin_settings('shown_interest_text');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('is_double_optin') && get_mvx_product_alert_old_plugin_settings('is_double_optin') == 'Enable' ) {
|
||||
$genaral_settings['is_double_optin'] = array('is_double_optin');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('is_remove_admin_email') && get_mvx_product_alert_old_plugin_settings('is_remove_admin_email') == 'Enable' ) {
|
||||
$genaral_settings['is_remove_admin_email'] = array('is_remove_admin_email');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('additional_alert_email') ) {
|
||||
$genaral_settings['additional_alert_email'] = get_mvx_product_alert_old_plugin_settings('additional_alert_email');
|
||||
}
|
||||
if ($genaral_settings) {
|
||||
save_mvx_product_alert_settings('mvx_woo_stock_alert_general_tab_settings', $genaral_settings);
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('alert_text') ) {
|
||||
$customization_settings['alert_text'] = get_mvx_product_alert_old_plugin_settings('alert_text');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('alert_text_color') ) {
|
||||
$customization_settings['alert_text_color'] = get_mvx_product_alert_old_plugin_settings('alert_text_color');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_text') ) {
|
||||
$customization_settings['button_text'] = get_mvx_product_alert_old_plugin_settings('button_text');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('unsubscribe_button_text') ) {
|
||||
$customization_settings['unsubscribe_button_text'] = get_mvx_product_alert_old_plugin_settings('unsubscribe_button_text');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_background_color') ) {
|
||||
$customization_settings['button_background_color'] = get_mvx_product_alert_old_plugin_settings('button_background_color');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_border_color') ) {
|
||||
$customization_settings['button_border_color'] = get_mvx_product_alert_old_plugin_settings('button_border_color');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_text_color') ) {
|
||||
$customization_settings['button_text_color'] = get_mvx_product_alert_old_plugin_settings('button_text_color');
|
||||
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_background_color_onhover') ) {
|
||||
$customization_settings['button_background_color_onhover'] = get_mvx_product_alert_old_plugin_settings('button_background_color_onhover');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_border_color_onhover') ) {
|
||||
$customization_settings['button_border_color_onhover'] = get_mvx_product_alert_old_plugin_settings('button_border_color_onhover');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_text_color_onhover') ) {
|
||||
$customization_settings['button_text_color_onhover'] = get_mvx_product_alert_old_plugin_settings('button_text_color_onhover');
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('button_font_size') ) {
|
||||
$customization_settings['button_font_size'] = get_mvx_product_alert_old_plugin_settings('button_font_size');
|
||||
}
|
||||
if ( $customization_settings ) {
|
||||
save_mvx_product_alert_settings('mvx_woo_stock_alert_form_customization_tab_settings', $customization_settings);
|
||||
}
|
||||
|
||||
if ( get_mvx_product_alert_old_plugin_settings('alert_success') ) {
|
||||
$submit_settings['alert_success'] = get_mvx_product_alert_old_plugin_settings('alert_success');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('alert_email_exist') ) {
|
||||
$submit_settings['alert_email_exist'] = get_mvx_product_alert_old_plugin_settings('alert_email_exist');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('valid_email') ) {
|
||||
$submit_settings['valid_email'] = get_mvx_product_alert_old_plugin_settings('valid_email');
|
||||
}
|
||||
if ( get_mvx_product_alert_old_plugin_settings('alert_unsubscribe_message') ) {
|
||||
$submit_settings['alert_unsubscribe_message'] = get_mvx_product_alert_old_plugin_settings('alert_unsubscribe_message');
|
||||
}
|
||||
if ($submit_settings) {
|
||||
save_mvx_product_alert_settings('mvx_woo_stock_alert_form_submission_tab_settings', $submit_settings);
|
||||
}
|
||||
|
||||
update_option('_is_updated_mvx_product_alert_settings', true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function migrate older subscription data
|
||||
*/
|
||||
function mvx_stock_alert_older_data_migration() {
|
||||
if (!get_option('_is_updated_mvx_product_alert_database')) {
|
||||
$all_products = array();
|
||||
$all_products = get_posts(
|
||||
array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => -1
|
||||
)
|
||||
);
|
||||
$all_product_ids = array();
|
||||
if (!empty($all_products) && is_array($all_products)) {
|
||||
foreach ($all_products as $products_each) {
|
||||
$child_ids = $product_obj = array();
|
||||
$product_obj = wc_get_product($products_each->ID);
|
||||
if ($product_obj && $product_obj->is_type('variable')) {
|
||||
if ($product_obj->has_child()) {
|
||||
$child_ids = $product_obj->get_children();
|
||||
if (isset($child_ids) && !empty($child_ids)) {
|
||||
foreach ($child_ids as $child_id) {
|
||||
$all_product_ids[] = $child_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$all_product_ids[] = $products_each->ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$get_subscribed_user = array();
|
||||
if (!empty($all_product_ids) && is_array($all_product_ids)) {
|
||||
foreach ($all_product_ids as $all_product_id) {
|
||||
$_product_subscriber = get_post_meta($all_product_id, '_product_subscriber', true);
|
||||
if ($_product_subscriber && !empty($_product_subscriber)) {
|
||||
$get_subscribed_user[$all_product_id] = get_post_meta($all_product_id, '_product_subscriber', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($get_subscribed_user) && is_array($get_subscribed_user)) {
|
||||
foreach ($get_subscribed_user as $id => $subscriber) {
|
||||
if (!empty($subscriber)) {
|
||||
foreach ($subscriber as $email) {
|
||||
insert_subscriber($email, $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_option('_is_updated_mvx_product_alert_database', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
class WOO_Product_Stock_Alert_Library {
|
||||
|
||||
public $lib_path;
|
||||
|
||||
public $lib_url;
|
||||
|
||||
public $php_lib_path;
|
||||
|
||||
public $php_lib_url;
|
||||
|
||||
public $jquery_lib_path;
|
||||
|
||||
public $jquery_lib_url;
|
||||
|
||||
public function __construct() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
|
||||
$this->lib_path = $WOO_Product_Stock_Alert->plugin_path . 'lib/';
|
||||
|
||||
$this->lib_url = $WOO_Product_Stock_Alert->plugin_url . 'lib/';
|
||||
|
||||
$this->php_lib_path = $this->lib_path . 'php/';
|
||||
|
||||
$this->php_lib_url = $this->lib_url . 'php/';
|
||||
|
||||
$this->jquery_lib_path = $this->lib_path . 'jquery/';
|
||||
|
||||
$this->jquery_lib_url = $this->lib_url . 'jquery/';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
|
||||
class WOO_Product_Stock_Alert_Shortcode {
|
||||
|
||||
public function __construct() {
|
||||
// Product Stock Alert Form Shortcode
|
||||
add_shortcode( 'display_stock_alert_form', array($this, 'display_stock_alert_form') );
|
||||
}
|
||||
function display_stock_alert_form($attr) {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$this->load_class('display-stock-alert-form');
|
||||
return $this->shortcode_wrapper(array('WOO_Product_Stock_Alert_Display_Form', 'output'), $attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcode Wrapper
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $function
|
||||
* @param array $atts (default: array())
|
||||
* @return string
|
||||
*/
|
||||
public function shortcode_wrapper($function, $atts = array()) {
|
||||
ob_start();
|
||||
call_user_func($function, $atts);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcode Class Loader
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $class_name
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function load_class($class_name = '') {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
if ('' != $class_name && '' != $WOO_Product_Stock_Alert->token) {
|
||||
require_once ('shortcode/class-' . esc_attr($WOO_Product_Stock_Alert->token) . '-shortcode-' . esc_attr($class_name) . '.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
if (!defined('ABSPATH'))
|
||||
exit;
|
||||
|
||||
/**
|
||||
* @class MVX Template Class
|
||||
*
|
||||
* @version 2.2.0
|
||||
* @package MultivendorX
|
||||
* @author MultiVendorX
|
||||
*/
|
||||
class WOO_Product_Stock_Alert_Template {
|
||||
|
||||
public $template_url;
|
||||
|
||||
public function __construct() {
|
||||
$this->template_url = 'woo-stock-alert/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get other templates (e.g. product attributes) passing attributes and including the file.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $template_name
|
||||
* @param array $args (default: array())
|
||||
* @param string $template_path (default: '')
|
||||
* @param string $default_path (default: '')
|
||||
* @return void
|
||||
*/
|
||||
public function get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
|
||||
|
||||
if ($args && is_array($args))
|
||||
extract($args);
|
||||
|
||||
$located = $this->locate_template($template_name, $template_path, $default_path);
|
||||
|
||||
include ($located);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate a template and return the path for inclusion.
|
||||
*
|
||||
* This is the load order:
|
||||
*
|
||||
* yourtheme / $template_path / $template_name
|
||||
* yourtheme / $template_name
|
||||
* $default_path / $template_name
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $template_name
|
||||
* @param string $template_path (default: '')
|
||||
* @param string $default_path (default: '')
|
||||
* @return string
|
||||
*/
|
||||
public function locate_template($template_name, $template_path = '', $default_path = '') {
|
||||
global $woocommerce, $WOO_Product_Stock_Alert;
|
||||
$default_path = apply_filters('template_path', $default_path);
|
||||
if (!$template_path) {
|
||||
$template_path = $this->template_url;
|
||||
}
|
||||
if (!$default_path) {
|
||||
$default_path = $WOO_Product_Stock_Alert->plugin_path . 'templates/';
|
||||
}
|
||||
// Look within passed path within the theme - this is priority
|
||||
$template = locate_template(array(trailingslashit($template_path) . $template_name, $template_name));
|
||||
// Add support of third perty plugin
|
||||
$template = apply_filters('mvx_locate_template', $template, $template_name, $template_path, $default_path);
|
||||
// Get default template
|
||||
if (!$template) {
|
||||
$template = $default_path . $template_name;
|
||||
}
|
||||
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get store templates (e.g. product attributes) passing attributes and including the file.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $template_name
|
||||
* @param array $args (default: array())
|
||||
* @param string $template_path (default: '')
|
||||
* @param string $default_path (default: '')
|
||||
* @return void
|
||||
*/
|
||||
public function get_store_template($template_name, $args = array(), $template_path = '', $default_path = '') {
|
||||
if ($args && is_array($args))
|
||||
extract($args);
|
||||
$located = $this->store_locate_template($template_name, $template_path, $default_path);
|
||||
include ($located);
|
||||
}
|
||||
|
||||
public function store_locate_template($template_name, $template_path = '', $default_path = '') {
|
||||
global $woocommerce, $WOO_Product_Stock_Alert;
|
||||
$default_path = apply_filters('template_path', $default_path);
|
||||
if (!$template_path) {
|
||||
$template_path = $this->template_url;
|
||||
}
|
||||
if (!$default_path) {
|
||||
$default_path = $WOO_Product_Stock_Alert->plugin_path . 'templates/';
|
||||
}
|
||||
// Look within passed path within the theme - this is priority
|
||||
$template = locate_template(array(trailingslashit($template_path) . $template_name, $template_name));
|
||||
// Add support of third perty plugin
|
||||
$template = apply_filters('mvx_store_locate_template', $template, $template_name, $template_path, $default_path);
|
||||
// Get default template
|
||||
if (!$template) {
|
||||
$template = $default_path . $template_name;
|
||||
}
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template part (for templates like the shop-loop).
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $slug
|
||||
* @param string $name (default: '')
|
||||
* @return void
|
||||
*/
|
||||
public function get_template_part($slug, $name = '') {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$template = '';
|
||||
|
||||
// Look in yourtheme/slug-name.php and yourtheme/woocommerce/slug-name.php
|
||||
if ($name)
|
||||
$template = $this->locate_template(array("{$slug}-{$name}.php", "{$this->template_url}{$slug}-{$name}.php"));
|
||||
|
||||
// Get default slug-name.php
|
||||
if (!$template && $name && file_exists($WOO_Product_Stock_Alert->plugin_path . "templates/{$slug}-{$name}.php"))
|
||||
$template = $WOO_Product_Stock_Alert->plugin_path . "templates/{$slug}-{$name}.php";
|
||||
|
||||
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/woocommerce/slug.php
|
||||
if (!$template)
|
||||
$template = $this->locate_template(array("{$slug}.php", "{$this->template_url}{$slug}.php"));
|
||||
|
||||
echo $template;
|
||||
|
||||
if ($template)
|
||||
load_template($template, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
class WOO_Product_Stock_Alert {
|
||||
|
||||
public $plugin_url;
|
||||
public $plugin_path;
|
||||
public $version;
|
||||
public $token;
|
||||
public $text_domain;
|
||||
public $frontend;
|
||||
public $ajax;
|
||||
public $templates;
|
||||
public $action;
|
||||
public $export;
|
||||
private $file;
|
||||
public $deprecated_hook_handlers = array();
|
||||
|
||||
public function __construct($file) {
|
||||
|
||||
$this->file = $file;
|
||||
$this->plugin_url = trailingslashit(plugins_url('', $plugin = $file));
|
||||
$this->plugin_path = trailingslashit(dirname($file));
|
||||
$this->token = WOO_PRODUCT_STOCK_ALERT_PLUGIN_TOKEN;
|
||||
$this->text_domain = WOO_PRODUCT_STOCK_ALERT_TEXT_DOMAIN;
|
||||
$this->version = WOO_PRODUCT_STOCK_ALERT_PLUGIN_VERSION;
|
||||
|
||||
add_action('init', array(&$this, 'init'), 0);
|
||||
// Woocommerce Email structure
|
||||
add_filter('woocommerce_email_classes', array(&$this, 'woo_product_stock_alert_mail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* initilize plugin on WP init
|
||||
*/
|
||||
function init() {
|
||||
// Init Text Domain
|
||||
$this->load_plugin_textdomain();
|
||||
|
||||
// Init library
|
||||
$this->load_class('library');
|
||||
$this->library = new WOO_Product_Stock_Alert_Library();
|
||||
|
||||
// Init ajax
|
||||
if (defined('DOING_AJAX')) {
|
||||
$this->load_class('ajax');
|
||||
$this->ajax = new WOO_Product_Stock_Alert_Ajax();
|
||||
}
|
||||
|
||||
if (is_admin()) {
|
||||
$this->load_class('admin');
|
||||
$this->admin = new WOO_Product_Stock_Alert_Admin();
|
||||
|
||||
$this->load_class('export');
|
||||
}
|
||||
|
||||
if (!is_admin() || defined('DOING_AJAX')) {
|
||||
$this->load_class('frontend');
|
||||
$this->frontend = new WOO_Product_Stock_Alert_Frontend();
|
||||
|
||||
$this->load_class('shortcode');
|
||||
$this->shortcode = new WOO_Product_Stock_Alert_Shortcode();
|
||||
}
|
||||
$this->load_class('template');
|
||||
$this->template = new WOO_Product_Stock_Alert_Template();
|
||||
|
||||
// Init action
|
||||
$this->load_class('action');
|
||||
$this->action = new WOO_Product_Stock_Alert_Action();
|
||||
|
||||
include_once $this->plugin_path . '/includes/class-woo-stock-alert-deprecated-filter-hooks.php';
|
||||
include_once $this->plugin_path . '/includes/class-woo-stock-alert-deprecated-action-hooks.php';
|
||||
include_once $this->plugin_path . '/includes/woo-stock-alert-deprecated-funtions.php';
|
||||
$this->deprecated_hook_handlers['filters'] = new Stock_Alert_Deprecated_Filter_Hooks();
|
||||
$this->deprecated_hook_handlers['actions'] = new Stock_Alert_Deprecated_Action_Hooks();
|
||||
|
||||
if (current_user_can('manage_options')) {
|
||||
add_action( 'rest_api_init', array( $this, 'stock_alert_rest_routes_react_module' ) );
|
||||
}
|
||||
|
||||
register_post_status('woo_mailsent', array(
|
||||
'label' => _x('Mail Sent', 'woostockalert', 'woocommerce-product-stock-alert'),
|
||||
'public' => true,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => true,
|
||||
'show_in_admin_status_list' => true,
|
||||
/* translators: %s: count */
|
||||
'label_count' => _n_noop('Mail Sent <span class="count">(%s)</span>', 'Mail Sent <span class="count">(%s)</span>', 'woocommerce-product-stock-alert'),
|
||||
));
|
||||
|
||||
register_post_status('woo_subscribed', array(
|
||||
'label' => _x('Subscribed', 'woostockalert', 'woocommerce-product-stock-alert'),
|
||||
'public' => true,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => true,
|
||||
'show_in_admin_status_list' => true,
|
||||
/* translators: %s: count */
|
||||
'label_count' => _n_noop('Subscribed <span class="count">(%s)</span>', 'Subscribed <span class="count">(%s)</span>'),
|
||||
));
|
||||
|
||||
register_post_status('woo_unsubscribed', array(
|
||||
'label' => _x('Unsubscribed', 'woostockalert', 'woocommerce-product-stock-alert'),
|
||||
'public' => true,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => true,
|
||||
'show_in_admin_status_list' => true,
|
||||
/* translators: %s: count */
|
||||
'label_count' => _n_noop('Unsubscribed <span class="count">(%s)</span>', 'Unsubscribed <span class="count">(%s)</span>'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load Localisation files.
|
||||
*
|
||||
* Note: the first-loaded translation file overrides any following ones if the same translation is present
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
|
||||
$locale = apply_filters('plugin_locale', $locale, 'woocommerce-product-stock-alert');
|
||||
load_textdomain('woocommerce-product-stock-alert', WP_LANG_DIR . '/woocommerce-product-stock-alert/woocommerce-product-stock-alert-' . $locale . '.mo');
|
||||
load_plugin_textdomain('woocommerce-product-stock-alert', false, plugin_basename(dirname(dirname(__FILE__))) . '/languages');
|
||||
}
|
||||
|
||||
public function load_class($class_name = '') {
|
||||
if ('' != $class_name && '' != $this->token) {
|
||||
require_once ('class-' . esc_attr($this->token) . '-' . esc_attr($class_name) . '.php');
|
||||
} // End If Statement
|
||||
}
|
||||
|
||||
/****************************Cache Helpers ******************************/
|
||||
/**
|
||||
* Sets a constant preventing some caching plugins from caching a page. Used on dynamic pages
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function nocache() {
|
||||
if (!defined('DONOTCACHEPAGE'))
|
||||
define("DONOTCACHEPAGE", "true");
|
||||
// WP Super Cache constant
|
||||
}
|
||||
|
||||
/**
|
||||
* Install upon activation
|
||||
*
|
||||
*/
|
||||
public static function activate_product_stock_alert() {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
|
||||
update_option('dc_product_stock_alert_installed', 1);
|
||||
|
||||
// Init install
|
||||
$WOO_Product_Stock_Alert->load_class('install');
|
||||
$WOO_Product_Stock_Alert->install = new WOO_Product_Stock_Alert_Install();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install upon deactivation
|
||||
*
|
||||
*/
|
||||
public static function deactivate_product_stock_alert() {
|
||||
|
||||
if (get_option('dc_product_stock_alert_cron_start')) :
|
||||
wp_clear_scheduled_hook('dc_start_stock_alert');
|
||||
delete_option('dc_product_stock_alert_cron_start');
|
||||
endif;
|
||||
delete_option('dc_product_stock_alert_installed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Stock Alert Email Class
|
||||
*
|
||||
*/
|
||||
function woo_product_stock_alert_mail($emails) {
|
||||
require_once( 'emails/class-woo-product-stock-alert-admin-email.php' );
|
||||
$emails['WC_Admin_Email_Stock_Alert'] = new WC_Admin_Email_Stock_Alert();
|
||||
require_once( 'emails/class-woo-product-stock-alert-subscriber-confirmation-email.php' );
|
||||
$emails['WC_Subscriber_Confirmation_Email_Stock_Alert'] = new WC_Subscriber_Confirmation_Email_Stock_Alert();
|
||||
require_once( 'emails/class-woo-product-stock-alert-email.php' );
|
||||
$emails['WC_Email_Stock_Alert'] = new WC_Email_Stock_Alert();
|
||||
|
||||
return $emails;
|
||||
}
|
||||
|
||||
public function stock_alert_rest_routes_react_module() {
|
||||
register_rest_route( 'mvx_stockalert/v1', '/fetch_admin_tabs', [
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'mvx_stockalert_fetch_admin_tabs' ),
|
||||
'permission_callback' => array( $this, 'stockalert_permission' ),
|
||||
] );
|
||||
register_rest_route( 'mvx_stockalert/v1', '/save_stockalert', [
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'mvx_stockalert_save_stockalert' ),
|
||||
'permission_callback' => array( $this, 'stockalert_permission' ),
|
||||
] );
|
||||
}
|
||||
|
||||
public function stockalert_permission() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function mvx_stockalert_fetch_admin_tabs() {
|
||||
$mvx_stockalert_tabs_data = mvx_stockalert_admin_tabs() ? mvx_stockalert_admin_tabs() : [];
|
||||
return rest_ensure_response( $mvx_stockalert_tabs_data );
|
||||
}
|
||||
|
||||
public function mvx_stockalert_save_stockalert($request) {
|
||||
$all_details = [];
|
||||
$modulename = $request->get_param('modulename');
|
||||
$modulename = str_replace("-", "_", $modulename);
|
||||
$get_managements_data = $request->get_param( 'model' );
|
||||
$optionname = 'mvx_woo_stock_alert_'.$modulename.'_tab_settings';
|
||||
update_option($optionname, $get_managements_data);
|
||||
do_action('mvx_woo_stock_alert_settings_after_save', $modulename, $get_managements_data);
|
||||
$all_details['error'] = __('Settings Saved', 'woocommerce-product-stock-alert');
|
||||
return $all_details;
|
||||
die;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WC_Admin_Email_Stock_Alert' ) ) :
|
||||
|
||||
/**
|
||||
* Email to Admin for stock alert
|
||||
*
|
||||
* An email will be sent to the admin when customer subscribe an out of stock product.
|
||||
*
|
||||
* @class WC_Admin_Email_Stock_Alert
|
||||
* @version 1.3.0
|
||||
* @author WC Marketplace
|
||||
* @extends WC_Email
|
||||
*/
|
||||
class WC_Admin_Email_Stock_Alert extends WC_Email {
|
||||
|
||||
public $product_id;
|
||||
public $customer_email;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
global $WOO_Product_Stock_Alert;
|
||||
|
||||
$this->id = 'stock_alert_admin';
|
||||
$this->title = __( 'Alert admin', 'woocommerce-product-stock-alert' );
|
||||
$this->description = __( 'Administrator otrzyma alert, gdy klient zasubskrybuje produkt niedostępny w magazynie.', 'woocommerce-product-stock-alert' );
|
||||
|
||||
$this->template_html = 'emails/stock_alert_admin_email.php';
|
||||
$this->template_plain = 'emails/plain/stock_alert_admin_email.php';
|
||||
|
||||
$this->template_base = $WOO_Product_Stock_Alert->plugin_path . 'templates/';
|
||||
|
||||
// Call parent constuctor
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function trigger( $recipient, $product_id, $customer_email ) {
|
||||
|
||||
$this->recipient = $recipient;
|
||||
$this->product_id = $product_id;
|
||||
$this->customer_email = $customer_email;
|
||||
|
||||
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email subject.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return apply_filters( 'woocommerce_email_subject_stock_alert', __( 'Klient zasubskrybował produkt na {site_title}', 'woocommerce-product-stock-alert'), $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email heading.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return apply_filters( 'woocommerce_email_heading_stock_alert', __( 'Witaj na {site_title}', 'woocommerce-product-stock-alert'),$this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_content_html function.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function get_content_html() {
|
||||
ob_start();
|
||||
wc_get_template( $this->template_html, array(
|
||||
'email_heading' => $this->get_heading(),
|
||||
'product_id' => $this->product_id,
|
||||
'customer_email' => $this->customer_email,
|
||||
'sent_to_admin' => true,
|
||||
'plain_text' => false,
|
||||
'email' => $this,
|
||||
), '', $this->template_base);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* get_content_plain function.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function get_content_plain() {
|
||||
ob_start();
|
||||
wc_get_template( $this->template_plain, array(
|
||||
'email_heading' => $this->get_heading(),
|
||||
'product_id' => $this->product_id,
|
||||
'customer_email' => $this->customer_email,
|
||||
'sent_to_admin' => true,
|
||||
'plain_text' => true
|
||||
) ,'', $this->template_base );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WC_Email_Stock_Alert' ) ) :
|
||||
|
||||
/**
|
||||
* Email for stock alert
|
||||
*
|
||||
* An email will be sent to the customer when their subscribed product is available.
|
||||
*
|
||||
* @class WC_Email_Stock_Alert
|
||||
* @version 1.3.0
|
||||
* @author WC Marketplace
|
||||
* @extends WC_Email
|
||||
*/
|
||||
class WC_Email_Stock_Alert extends WC_Email {
|
||||
|
||||
public $product_id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
global $WOO_Product_Stock_Alert;
|
||||
|
||||
$this->id = 'stock_alert';
|
||||
$this->title = __( 'Abonent Alert', 'woocommerce-product-stock-alert' );
|
||||
$this->description = __( 'Powiadomienie klienta, gdy ich zasubskrybowany produkt będzie dostępny w magazynie', 'woocommerce-product-stock-alert' );
|
||||
|
||||
$this->template_html = 'emails/stock_alert_email.php';
|
||||
$this->template_plain = 'emails/plain/stock_alert_email.php';
|
||||
|
||||
$this->template_base = $WOO_Product_Stock_Alert->plugin_path . 'templates/';
|
||||
|
||||
// Call parent constuctor
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function trigger( $recipient, $product_id ) {
|
||||
|
||||
$this->customer_email = $recipient;
|
||||
$this->recipient = $recipient;
|
||||
$this->product_id = $product_id;
|
||||
|
||||
if (get_mvx_product_alert_plugin_settings('is_remove_admin_email') == false) {
|
||||
$this->recipient .= ',' . get_option('admin_email');
|
||||
}
|
||||
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email subject.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return apply_filters( 'woocommerce_email_subject_stock_alert', __( 'Twój zasubskrybowany produkt na {site_title} jest teraz dostępny.', 'woocommerce-product-stock-alert'), $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email heading.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return apply_filters( 'woocommerce_email_heading_stock_alert', __( 'Witaj na {site_title}!', 'woocommerce-product-stock-alert'), $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_content_html function.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function get_content_html() {
|
||||
ob_start();
|
||||
wc_get_template( $this->template_html, array(
|
||||
'email_heading' => $this->get_heading(),
|
||||
'product_id' => $this->product_id,
|
||||
'customer_email' => $this->customer_email,
|
||||
'sent_to_admin' => false,
|
||||
'plain_text' => false,
|
||||
'email' => $this,
|
||||
), '', $this->template_base);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* get_content_plain function.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function get_content_plain() {
|
||||
ob_start();
|
||||
wc_get_template( $this->template_plain, array(
|
||||
'email_heading' => $this->get_heading(),
|
||||
'product_id' => $this->product_id,
|
||||
'customer_email' => $this->customer_email,
|
||||
'sent_to_admin' => false,
|
||||
'plain_text' => true
|
||||
) ,'', $this->template_base );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'WC_Subscriber_Confirmation_Email_Stock_Alert' ) ) :
|
||||
|
||||
/**
|
||||
* Email for stock alert
|
||||
*
|
||||
* An confirmation email will be sent to the customer when they subscribe product.
|
||||
*
|
||||
* @class WC_Subscriber_Confirmation_Email_Stock_Alert
|
||||
* @version 1.3.0
|
||||
* @author WC Marketplace
|
||||
* @extends WC_Email
|
||||
*/
|
||||
class WC_Subscriber_Confirmation_Email_Stock_Alert extends WC_Email {
|
||||
|
||||
public $product_id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
global $WOO_Product_Stock_Alert;
|
||||
|
||||
$this->id = 'stock_alert_subscriber_confirmation';
|
||||
$this->title = __( 'Potwierdź subskrybenta', 'woocommerce-product-stock-alert' );
|
||||
$this->description = __( 'Potwierdź klienta, gdy zasubskrybuje produkt', 'woocommerce-product-stock-alert' );
|
||||
|
||||
$this->template_html = 'emails/stock_alert_email_subscriber_confirmation.php';
|
||||
$this->template_plain = 'emails/plain/stock_alert_email_subscriber_confirmation.php';
|
||||
|
||||
$this->template_base = $WOO_Product_Stock_Alert->plugin_path . 'templates/';
|
||||
|
||||
// Call parent constuctor
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function trigger( $recipient, $product_id ) {
|
||||
|
||||
$this->recipient = $recipient;
|
||||
$this->product_id = $product_id;
|
||||
|
||||
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email subject.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return apply_filters( 'woocommerce_email_subject_stock_alert', __( 'Zasubskrybowałeś produkt na {site_title}', 'woocommerce-product-stock-alert'), $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email heading.
|
||||
*
|
||||
* @since 1.4.7
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return apply_filters( 'woocommerce_email_heading_stock_alert', __( 'Witaj na {site_title}', 'woocommerce-product-stock-alert'), $this->object );
|
||||
}
|
||||
|
||||
/**
|
||||
* get_content_html function.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function get_content_html() {
|
||||
ob_start();
|
||||
wc_get_template( $this->template_html, array(
|
||||
'email_heading' => $this->get_heading(),
|
||||
'product_id' => $this->product_id,
|
||||
'customer_email' => $this->recipient,
|
||||
'sent_to_admin' => false,
|
||||
'plain_text' => false,
|
||||
'email' => $this,
|
||||
), '', $this->template_base);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* get_content_plain function.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function get_content_plain() {
|
||||
ob_start();
|
||||
wc_get_template( $this->template_plain, array(
|
||||
'email_heading' => $this->get_heading(),
|
||||
'product_id' => $this->product_id,
|
||||
'customer_email' => $this->recipient,
|
||||
'sent_to_admin' => false,
|
||||
'plain_text' => true
|
||||
) ,'', $this->template_base );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
class WOO_Product_Stock_Alert_Display_Form {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Stock Alert Form
|
||||
*
|
||||
* @access public
|
||||
* @param array $atts
|
||||
* @return void
|
||||
*/
|
||||
public static function output($attr) {
|
||||
global $WOO_Product_Stock_Alert;
|
||||
$WOO_Product_Stock_Alert->nocache();
|
||||
$frontend_script_path = $WOO_Product_Stock_Alert->plugin_url . 'assets/frontend/js/';
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '';
|
||||
|
||||
do_action('woocommerce_product_stock_alert_form_before');
|
||||
|
||||
global $product;
|
||||
|
||||
if (empty($product))
|
||||
return;
|
||||
|
||||
if ($product->is_type('simple')) {
|
||||
echo _e( $WOO_Product_Stock_Alert->frontend->display_subscribe_box( $product ) );
|
||||
} else if ($product->is_type('variable')) {
|
||||
$stock_interest = $alert_text_html = $button_html = $button_css = '';
|
||||
$settings_array = get_woo_form_settings_array();
|
||||
|
||||
if (!empty($settings_array['alert_text'])) {
|
||||
$alert_text_html = '<h5 style="color:' . $settings_array['alert_text_color'] . '" class="subscribe_for_interest_text">' . $settings_array['alert_text'] . '</h5>';
|
||||
} else {
|
||||
$alert_text_html = '<h5 class="subscribe_for_interest_text">' . $settings_array['alert_text'] . '</h5>';
|
||||
}
|
||||
|
||||
if (!empty($settings_array['button_background_color']))
|
||||
$button_css .= "background:" . $settings_array['button_background_color'] . ";";
|
||||
if (!empty($settings_array['button_text_color']))
|
||||
$button_css .= "color:" . $settings_array['button_text_color'] . ";";
|
||||
if (!empty($settings_array['button_border_color']))
|
||||
$button_css .= "border: 1px solid" . $settings_array['button_border_color'] . ";";
|
||||
if (!empty($settings_array['button_text_color']))
|
||||
$button_css .= "font-size:" . $settings_array['button_font_size'] . ";";
|
||||
|
||||
|
||||
if (!empty($button_css)) {
|
||||
$button_html = '<button style="' . $button_css .';" class="stock_alert_button alert_button_hover" name="alert_button">' . $settings_array['button_text'] . '</button>';
|
||||
$unsubscribe_button_html = '<button class="unsubscribe_button" style="' . $button_css .';">' . $settings_array['unsubscribe_button_text'] . '</button>';
|
||||
} else {
|
||||
$button_html = '<button class="stock_alert_button" name="alert_button">' . $settings_array['button_text'] . '</button>';
|
||||
$unsubscribe_button_html = '<button class="unsubscribe_button">' . $settings_array['unsubscribe_button_text'] . '</button>';
|
||||
}
|
||||
if (function_exists('is_product')) {
|
||||
if (is_product()) {
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
// Enqueue your frontend javascript from here
|
||||
wp_enqueue_script('stock_alert_shortcode_js', $frontend_script_path . 'shortcode' . $suffix . '.js', array('jquery'), $WOO_Product_Stock_Alert->version, true);
|
||||
|
||||
wp_localize_script('stock_alert_shortcode_js', 'stock_alert_sc_data', array('ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
||||
'product_id' => $product->get_id(),
|
||||
'product_title' => $product->get_title(),
|
||||
'additional_fields' => apply_filters('woocommerce_product_stock_alert_form_additional_fields', []),
|
||||
'alert_text_html' => $alert_text_html,
|
||||
'button_html' => $button_html,
|
||||
));
|
||||
}
|
||||
}
|
||||
echo '<div class="stock_notifier-shortcode-subscribe-form"></div>';
|
||||
} else {
|
||||
echo _e( $WOO_Product_Stock_Alert->frontend->display_subscribe_box( $product ) );
|
||||
}
|
||||
|
||||
do_action('woocommerce_product_stock_alert_form_after');
|
||||
|
||||
// remove default stock alert position
|
||||
remove_action( 'woocommerce_simple_add_to_cart', array( $WOO_Product_Stock_Alert->frontend, 'display_in_simple_product' ), 31 );
|
||||
remove_action( 'woocommerce_bundle_add_to_cart', array( $WOO_Product_Stock_Alert->frontend, 'display_in_simple_product' ), 31 );
|
||||
remove_action( 'woocommerce_woosb_add_to_cart', array( $WOO_Product_Stock_Alert->frontend, 'display_in_simple_product' ), 31 );
|
||||
remove_action( 'woocommerce_after_variations_form', array( $WOO_Product_Stock_Alert->frontend, 'display_in_no_variation_product' ) );
|
||||
remove_action( 'woocommerce_grouped_add_to_cart', array( $WOO_Product_Stock_Alert->frontend, 'display_in_simple_product' ), 32 );
|
||||
remove_filter( 'woocommerce_available_variation', array( $WOO_Product_Stock_Alert->frontend, 'display_in_variation' ), 10, 3 );
|
||||
// Some theme variation disabled by default if it is out of stock so for that workaround solution.
|
||||
remove_filter( 'woocommerce_variation_is_active', array( $WOO_Product_Stock_Alert->frontend, 'enable_disabled_variation_dropdown' ), 100, 2 );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user