=1?"floor":"ceil"](d/o),f=Math[f>=1?"floor":"ceil"](f/o),c=Math[c>=1?"floor":"ceil"](c/o),l.settings.normalizeOffset&&this.getBoundingClientRect){var v=this.getBoundingClientRect();h=t.clientX-v.left,g=t.clientY-v.top}return t.deltaX=f,t.deltaY=c,t.deltaFactor=o,t.offsetX=h,t.offsetY=g,t.deltaMode=0,s.unshift(t,d,f,c),n&&clearTimeout(n),n=setTimeout(a,200),(e.event.dispatch||e.event.handle).apply(this,s)}}function a(){o=null}function r(e,t){return l.settings.adjustOldDeltas&&"mousewheel"===e.type&&t%120==0}var n,o,i=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],s="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],u=Array.prototype.slice;if(e.event.fixHooks)for(var d=i.length;d;)e.event.fixHooks[i[--d]]=e.event.mouseHooks;var l=e.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var a=s.length;a;)this.addEventListener(s[--a],t,!1);else this.onmousewheel=t;e.data(this,"mousewheel-line-height",l.getLineHeight(this)),e.data(this,"mousewheel-page-height",l.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var a=s.length;a;)this.removeEventListener(s[--a],t,!1);else this.onmousewheel=null;e.removeData(this,"mousewheel-line-height"),e.removeData(this,"mousewheel-page-height")},getLineHeight:function(t){var a=e(t),r=a["offsetParent"in e.fn?"offsetParent":"parent"]();return r.length||(r=e("body")),parseInt(r.css("fontSize"),10)||parseInt(a.css("fontSize"),10)||16},getPageHeight:function(t){return e(t).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};e.fn.extend({mousewheel:function(e){return e?this.bind("mousewheel",e):this.trigger("mousewheel")},unmousewheel:function(e){return this.unbind("mousewheel",e)}})});
\ No newline at end of file
diff --git a/admin/assets/js/offers-for-woocommerce-admin.js b/admin/assets/js/offers-for-woocommerce-admin.js
index bb4c57d8..f29006ad 100644
--- a/admin/assets/js/offers-for-woocommerce-admin.js
+++ b/admin/assets/js/offers-for-woocommerce-admin.js
@@ -17,13 +17,6 @@ jQuery(function ($) {
notify_wordpress(jQuery(this).data("msg"));
});
- jQuery("#enable_binding_offer_authorization").change(function () {
- if (jQuery(this).is(':checked')) {
- jQuery('#enable_make_offer_payment_authorization').closest('tr').show();
- } else{
- jQuery('#enable_make_offer_payment_authorization').closest('tr').hide();
- }
- }).change();
});
function notify_wordpress(message) {
diff --git a/admin/class-offers-for-woocommerce-admin.php b/admin/class-offers-for-woocommerce-admin.php
index ba5026d1..5983ceb3 100644
--- a/admin/class-offers-for-woocommerce-admin.php
+++ b/admin/class-offers-for-woocommerce-admin.php
@@ -84,13 +84,19 @@ private function __construct() {
* XXX
* @since 0.1.0
*/
- add_action('manage_woocommerce_offer_posts_custom_column', array($this, 'get_woocommerce_offer_column'), 2, 10);
+ add_action('manage_woocommerce_offer_posts_custom_column', array(
+ $this,
+ 'get_woocommerce_offer_column'
+ ), 2, 10);
/**
* XXX
* @since 0.1.0
*/
- add_filter('manage_edit-woocommerce_offer_sortable_columns', array($this, 'woocommerce_offer_sortable_columns'));
+ add_filter('manage_edit-woocommerce_offer_sortable_columns', array(
+ $this,
+ 'woocommerce_offer_sortable_columns'
+ ));
/**
* XXX
@@ -116,7 +122,6 @@ private function __construct() {
*/
add_filter('post_row_actions', array($this, 'remove_quick_edit'), 10, 2);
-
/**
* XXX
* @since 0.1.0
@@ -316,7 +321,6 @@ private function __construct() {
*/
add_action('wp_ajax_adminToolBulkEnableDisable', array($this, 'adminToolBulkEnableDisableCallback'));
-
add_action('wp_ajax_adminToolSetMinimumOfferPrice', array($this, 'adminToolSetMinimumOfferPriceCallback'));
/*
@@ -428,11 +432,44 @@ private function __construct() {
add_action('admin_action_editpost', array($this, 'angelleye_offer_for_woocommerce_admin_save_offer'), 10);
add_action('angelleye_display_extra_product_details', array($this, 'angelleye_offer_for_woocommerce_display_product_extra_details'), 10, 1);
add_action('angelleye_display_extra_product_details_email', array($this, 'angelleye_offer_for_woocommerce_display_product_extra_details_email'), 10, 1);
-
+ /**
+ * Change SEO Title for Woocommerce_Offers when Anonymous Communication is enabled
+ * @since 2.3.18
+ */
+ add_filter('wpseo_title', array($this, 'change_woocommerce_offer_seo_title'));
+
+ /**
+ * Email Reminders
+ */
+ add_action('admin_enqueue_scripts', __class__ . '::load_email_templates_script', 15);
}
// END - construct
+ /**
+ * Change SEO Title for Woocommerce_Offers when Anonymous Communication is enabled
+ *
+ * @param $title
+ *
+ * @return string
+ * @since 2.3.18
+ */
+ function change_woocommerce_offer_seo_title($title) {
+ $post_type = get_post_type();
+ if (isset($post_type) && 'woocommerce_offer' == $post_type && $this->ofw_is_anonymous_communication_enable()) {
+ $id = get_the_ID();
+ $product_id = get_post_meta($id, 'orig_offer_product_id', true);
+ $new_title = '';
+ if (!empty($product_id)) {
+ $product = wc_get_product($product_id);
+ $new_title = $product->get_name();
+ }
+ $title = !empty($new_title) ? $new_title . '-Offer' : 'Offer';
+ }
+
+ return $title;
+ }
+
function ofw_before_offers_trash_action($offer_id) {
if ('woocommerce_offer' !== get_post_type($offer_id)) {
return;
@@ -572,14 +609,26 @@ function add_user_menu_bubble() {
function add_offers_submenu_children() {
$offers_manage_link_href = admin_url('edit.php?post_type=woocommerce_offer');
$offers_settings_link_href = admin_url('options-general.php?page=offers-for-woocommerce');
+
+ $li_html = array();
+ $li_html['manage_offer'] = '';
+ $li_html['ofw_settings'] = '';
+
+ $li_html = apply_filters('aeofwc_offer_submenu_link_html', $li_html);
+ $html = '';
+
global $submenu;
if (isset($submenu['woocommerce']) && !empty($submenu['woocommerce'])) {
foreach ($submenu['woocommerce'] as $key => $value) {
if ($submenu['woocommerce'][$key][2] == 'edit.php?post_type=woocommerce_offer') {
// Add child submenu html
$submenu['woocommerce'][$key][0] .= "";
}
}
@@ -664,7 +713,6 @@ function custom_tab_options_offers() {
$post_meta_auto_accept_percentage = get_post_meta($post->ID, '_offers_for_woocommerce_auto_accept_percentage', true);
$post_meta_auto_accept_percentage_value = ($post_meta_auto_accept_percentage) ? $post_meta_auto_accept_percentage : '';
-
/**
* Auto Decline Offer
*/
@@ -676,7 +724,7 @@ function custom_tab_options_offers() {
?>
- $field_value, 'cbvalue' => $field_callback, 'id' => 'offers_for_woocommerce_enabled', 'label' => __('Enable Offers?', 'offers-for-woocommerce'), 'desc_tip' => 'true', 'description' => __('Enable this option to enable the \'Make Offer\' buttons and form display in the shop.', 'offers-for-woocommerce'))); ?>
+ $field_value, 'cbvalue' => $field_callback, 'id' => 'offers_for_woocommerce_enabled', 'label' => __('Enable Offers?', 'offers-for-woocommerce'), 'desc_tip' => 'true', 'description' => __('Enable this option to enable the \'Make Offer\' buttons and form display in the shop.', 'offers-for-woocommerce'))); ?>
$field_value, 'cbvalue' => $field_callback_onexit_only, 'id' => 'offers_for_woocommerce_onexit_only', 'label' => __('On Exit Only?', 'offers-for-woocommerce'), 'desc_tip' => 'true', 'description' => __('Enable this option to display the \'Make Offer\' form only when the user is about to exit the page.', 'offers-for-woocommerce'))); ?>
@@ -689,1806 +737,1777 @@ function custom_tab_options_offers() {
$field_value_auto_decline_enabled, 'cbvalue' => $field_callback_auto_decline_enabled, 'id' => '_offers_for_woocommerce_auto_decline_enabled', 'label' => __('Enable Auto Decline Offers?', 'offers-for-woocommerce'), 'desc_tip' => 'true', 'description' => __('Enable this option to automatically decline offers based on the percentage set.', 'offers-for-woocommerce'))); ?>
plugin_url()) . '/assets/images/help.png" height="16" width="16" />'; ?>
+
+ ID, $post); ?>
+
- '', // Unused. Messages start at index 1.
- 1 => __('Offer updated.', 'offers-for-woocommerce'),
- 2 => __('Offer Details updated.', 'offers-for-woocommerce'),
- 3 => __('Offer Details deleted.', 'offers-for-woocommerce'),
- 4 => __('Offer updated.', 'offers-for-woocommerce'),
- /* translators: %s: date and time of the revision */
- 5 => isset($_GET['revision']) ? sprintf(__('Offer restored to revision from %s', 'offers-for-woocommerce'), wp_post_revision_title((int) wc_clean($_GET['revision']), false)) : false,
- 6 => __('Offer set as Pending Status.', 'offers-for-woocommerce'),
- 7 => __('Offer saved.', 'offers-for-woocommerce'),
- 8 => __('Offer submitted.', 'offers-for-woocommerce'),
- 9 => sprintf(
- __('Offer scheduled for: %1$s .', 'offers-for-woocommerce'),
- // translators: Publish box date format, see http://php.net/date
- date_i18n(__('M j, Y @ G:i', 'offers-for-woocommerce'), strtotime($post->post_date))
- ),
- 10 => __('Offer draft updated.', 'offers-for-woocommerce'),
- 11 => __('Offer note added.', 'offers-for-woocommerce')
- );
+ /**
+ * Override updated message for custom post type
+ *
+ * @param array $messages Existing post update messages.
+ *
+ * @return array Amended post update messages with new CPT update messages.
+ * @since 0.1.0
+ */
+ public function my_custom_updated_messages($messages) {
+ $post = get_post();
+ $post_type = get_post_type($post);
+ $post_type_object = get_post_type_object($post_type);
+
+ $messages['woocommerce_offer'] = array(
+ 0 => '', // Unused. Messages start at index 1.
+ 1 => __('Offer updated.', 'offers-for-woocommerce'),
+ 2 => __('Offer Details updated.', 'offers-for-woocommerce'),
+ 3 => __('Offer Details deleted.', 'offers-for-woocommerce'),
+ 4 => __('Offer updated.', 'offers-for-woocommerce'),
+ /* translators: %s: date and time of the revision */
+ 5 => isset($_GET['revision']) ? sprintf(__('Offer restored to revision from %s', 'offers-for-woocommerce'), wp_post_revision_title((int) wc_clean($_GET['revision']), false)) : false,
+ 6 => __('Offer set as Pending Status.', 'offers-for-woocommerce'),
+ 7 => __('Offer saved.', 'offers-for-woocommerce'),
+ 8 => __('Offer submitted.', 'offers-for-woocommerce'),
+ 9 => sprintf(
+ __('Offer scheduled for: %1$s .', 'offers-for-woocommerce'),
+ // translators: Publish box date format, see http://php.net/date
+ date_i18n(__('M j, Y @ G:i', 'offers-for-woocommerce'), strtotime($post->post_date))
+ ),
+ 10 => __('Offer draft updated.', 'offers-for-woocommerce'),
+ 11 => __('Offer note added.', 'offers-for-woocommerce')
+ );
- return $messages;
- }
+ return $messages;
+ }
- /**
- * Filter - Remove meta boxes not needed on edit detail view
- * @since 0.1.0
- */
- public function remove_woocommerce_offer_meta_boxes() {
- $hidden = array(
- 'posttitle',
- 'submitdiv',
- 'categorydiv',
- 'formatdiv',
- 'pageparentdiv',
- 'postimagediv',
- 'tagsdiv-post_tag',
- 'postexcerpt',
- 'slugdiv',
- 'trackbacksdiv',
- 'commentstatusdiv',
- 'commentsdiv',
- 'authordiv',
- 'revisionsdiv');
-
- foreach ($hidden as $item) {
- remove_meta_box($item, 'woocommerce_offer', 'normal');
+ /**
+ * Filter - Remove meta boxes not needed on edit detail view
+ * @since 0.1.0
+ */
+ public function remove_woocommerce_offer_meta_boxes() {
+ $hidden = array(
+ 'posttitle',
+ 'submitdiv',
+ 'categorydiv',
+ 'formatdiv',
+ 'pageparentdiv',
+ 'postimagediv',
+ 'tagsdiv-post_tag',
+ 'postexcerpt',
+ 'slugdiv',
+ 'trackbacksdiv',
+ 'commentstatusdiv',
+ 'commentsdiv',
+ 'authordiv',
+ 'revisionsdiv');
+
+ foreach ($hidden as $item) {
+ remove_meta_box($item, 'woocommerce_offer', 'normal');
+ }
}
- }
- /**
- * Filter - Remove submenu "Add New"
- * @since 0.1.0
- * @NOTE: Removes 'Add New' submenu part from the submenu array
- */
- public function my_remove_submenus() {
- global $submenu;
- unset($submenu['edit.php?post_type=woocommerce_offer'][10]); // Removes 'Add New' submenu part from the submenu array
- }
+ /**
+ * Filter - Remove submenu "Add New"
+ * @since 0.1.0
+ * @NOTE: Removes 'Add New' submenu part from the submenu array
+ */
+ public function my_remove_submenus() {
+ global $submenu;
+ unset($submenu['edit.php?post_type=woocommerce_offer'][10]); // Removes 'Add New' submenu part from the submenu array
+ }
- /**
- * Filter - Modify the comments clause - to exclude "woocommerce_offer" post type
- * @since 0.1.0
- * @param array $clauses
- * @param object $wp_comment_query
- * @return array
- */
- public function angelleye_ofwc_exclude_cpt_from_comments_clauses($clauses) {
- require_once(ABSPATH . 'wp-admin/includes/screen.php');
- $screen = get_current_screen();
- if (!empty($screen->id) && $screen->id == 'edit-comments') {
- global $wpdb;
- $clauses['join'] = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
- $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type <> '%s'", 'woocommerce_offer');
- return $clauses;
- } else {
- return $clauses;
+ /**
+ * Filter - Modify the comments clause - to exclude "woocommerce_offer" post type
+ * @since 0.1.0
+ * @param array $clauses
+ * @param object $wp_comment_query
+ * @return array
+ */
+ public function angelleye_ofwc_exclude_cpt_from_comments_clauses($clauses) {
+ require_once(ABSPATH . 'wp-admin/includes/screen.php');
+ $screen = get_current_screen();
+ if (!empty($screen->id) && $screen->id == 'edit-comments') {
+ global $wpdb;
+ $clauses['join'] = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
+ $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type <> '%s'", 'woocommerce_offer');
+ return $clauses;
+ } else {
+ return $clauses;
+ }
}
- }
- /**
- * Set custom columns on CPT edit list view
- * @since 0.1.0
- */
- public function set_woocommerce_offer_columns($columns) {
- if (!$this->ofw_is_anonymous_communication_enable()) {
- $columns['offer_name'] = __('Name', 'offers-for-woocommerce');
+ /**
+ * Set custom columns on CPT edit list view
+ * @since 0.1.0
+ */
+ public function set_woocommerce_offer_columns($columns) {
+ if (!$this->ofw_is_anonymous_communication_enable()) {
+ $columns['offer_name'] = __('Name', 'offers-for-woocommerce');
+ }
+ $columns['offer_product_title'] = __('Product', 'offers-for-woocommerce');
+ $columns['offer_amount'] = __('Amount', 'offers-for-woocommerce');
+ $columns['offer_price_per'] = __('Price Per', 'offers-for-woocommerce');
+ $columns['offer_quantity'] = __('Quantity', 'offers-for-woocommerce');
+ return $columns;
}
- $columns['offer_product_title'] = __('Product', 'offers-for-woocommerce');
- $columns['offer_amount'] = __('Amount', 'offers-for-woocommerce');
- $columns['offer_price_per'] = __('Price Per', 'offers-for-woocommerce');
- $columns['offer_quantity'] = __('Quantity', 'offers-for-woocommerce');
- return $columns;
- }
- /**
- * Get custom columns data for CPT edit list view
- * @since 0.1.0
- */
- public function get_woocommerce_offer_column($column, $post_id) {
- $post_status = get_post_status($post_id);
- $offer_currency = get_post_meta($post_id, 'offer_currency', true);
- if( empty($offer_currency) ) {
- $offer_currency = get_woocommerce_currency();
- }
- switch ($column) {
- case 'offer_name' :
- $val = get_post_meta($post_id, 'offer_name', true);
- echo stripslashes($val);
- break;
- case 'offer_product_title' :
- $product_id = get_post_meta($post_id, 'orig_offer_product_id', true);
- $product_variant_id = get_post_meta($post_id, 'orig_offer_product_id', true);
- $wc_prd_vendor_options = get_option('wc_prd_vendor_options');
- if (!empty($wc_prd_vendor_options)) {
- $can_edit_opt = $wc_prd_vendor_options['can_edit_published_products'];
- } else {
- $can_edit_opt = false;
- }
- $user = wp_get_current_user();
+ /**
+ * Get custom columns data for CPT edit list view
+ * @since 0.1.0
+ */
+ public function get_woocommerce_offer_column($column, $post_id) {
+ $post_status = get_post_status($post_id);
+ $offer_currency = get_post_meta($post_id, 'offer_currency', true);
+ if (empty($offer_currency)) {
+ $offer_currency = get_woocommerce_currency();
+ }
+ switch ($column) {
+ case 'offer_name' :
+ $val = get_post_meta($post_id, 'offer_name', true);
+ echo stripslashes($val);
+ break;
+ case 'offer_product_title' :
+ $product_id = get_post_meta($post_id, 'orig_offer_product_id', true);
+ $product_variant_id = get_post_meta($post_id, 'orig_offer_product_id', true);
+ $wc_prd_vendor_options = get_option('wc_prd_vendor_options');
+ if (!empty($wc_prd_vendor_options)) {
+ $can_edit_opt = $wc_prd_vendor_options['can_edit_published_products'];
+ } else {
+ $can_edit_opt = false;
+ }
+ $user = wp_get_current_user();
- if ($product_id > 0) {
- $product_title = get_the_title($product_id);
- if (in_array('vendor', (array) $user->roles)) {
- if (isset($can_edit_opt) && $can_edit_opt == 1) {
- $val = '' . $product_title . ' ';
+ if ($product_id > 0) {
+ $product_title = get_the_title($product_id);
+ if (in_array('vendor', (array) $user->roles)) {
+ if (isset($can_edit_opt) && $can_edit_opt == 1) {
+ $val = '' . $product_title . ' ';
+ } else {
+ $val = $product_title;
+ }
} else {
- $val = $product_title;
+ $val = '' . $product_title . ' ';
}
} else {
- $val = '' . $product_title . ' ';
+ $val = '' . __('Not Found', 'offers-for-woocommerce') . ' ';
}
- } else {
- $val = '' . __('Not Found', 'offers-for-woocommerce') . ' ';
- }
-
- echo stripslashes($val);
- break;
-
- case 'offer_quantity' :
- if ($post_status == 'buyercountered-offer') {
- $val = get_post_meta($post_id, 'offer_buyer_counter_quantity', true);
- } else {
- $val = get_post_meta($post_id, 'offer_quantity', true);
- }
- $val = ($val != '') ? $val : '0';
- echo $val;
- break;
-
- case 'offer_price_per' :
- if ($post_status == 'buyercountered-offer') {
- $val = get_post_meta($post_id, 'offer_buyer_counter_price_per', true);
- } else {
- $val = get_post_meta($post_id, 'offer_price_per', true);
- }
- $val = ($val != '') ? $val : '0';
- echo wc_price($val, array('currency' => $offer_currency));
- break;
-
- case 'offer_amount' :
- if ($post_status == 'buyercountered-offer') {
- $val = get_post_meta($post_id, 'offer_buyer_counter_amount', true);
- } else {
- $val = get_post_meta($post_id, 'offer_amount', true);
- }
- $val = ($val != '') ? $val : '0';
- echo wc_price($val, array('currency' => $offer_currency));
- break;
- }
- }
- /**
- * Filter the custom columns for CPT edit list view to be sortable
- * @since 0.1.0
- */
- public function woocommerce_offer_sortable_columns($columns) {
- $columns['offer_email'] = 'offer_email';
- $columns['offer_name'] = 'offer_name';
- $columns['offer_product_title'] = 'orig_offer_product_id';
- $columns['offer_price_per'] = 'offer_price_per';
- $columns['offer_quantity'] = 'offer_quantity';
- $columns['offer_amount'] = 'offer_amount';
- return $columns;
- }
+ echo stripslashes($val);
+ break;
- /*
- * ADMIN COLUMN - SORTING - ORDERBY
- * http://scribu.net/wordpress/custom-sortable-columns.html#comment-4732
- */
+ case 'offer_quantity' :
+ if ($post_status == 'buyercountered-offer') {
+ $val = get_post_meta($post_id, 'offer_buyer_counter_quantity', true);
+ } else {
+ $val = get_post_meta($post_id, 'offer_quantity', true);
+ }
+ $val = ($val != '') ? $val : '0';
+ echo $val;
+ break;
- public function woocommerce_offers_list_orderby($vars) {
+ case 'offer_price_per' :
+ if ($post_status == 'buyercountered-offer') {
+ $val = get_post_meta($post_id, 'offer_buyer_counter_price_per', true);
+ } else {
+ $val = get_post_meta($post_id, 'offer_price_per', true);
+ }
+ $val = ($val != '') ? $val : '0';
+ echo wc_price($val, array('currency' => $offer_currency));
+ break;
- if(!is_admin()) {
- return $vars;
+ case 'offer_amount' :
+ if ($post_status == 'buyercountered-offer') {
+ $val = get_post_meta($post_id, 'offer_buyer_counter_amount', true);
+ } else {
+ $val = get_post_meta($post_id, 'offer_amount', true);
+ }
+ $val = ($val != '') ? $val : '0';
+ echo wc_price($val, array('currency' => $offer_currency));
+ break;
+ }
}
/**
- * Below if condition will check for the $vars retrun while they are empty array.
- * Reason behind adding this Line is Static Fron page will be redirect to Blog page.
- * Issue's more info : https://github.com/angelleye/offers-for-woocommerce/issues/319
- * */
- if (empty($vars)) {
- return $vars;
+ * Filter the custom columns for CPT edit list view to be sortable
+ * @since 0.1.0
+ */
+ public function woocommerce_offer_sortable_columns($columns) {
+ $columns['offer_email'] = 'offer_email';
+ $columns['offer_name'] = 'offer_name';
+ $columns['offer_product_title'] = 'orig_offer_product_id';
+ $columns['offer_price_per'] = 'offer_price_per';
+ $columns['offer_quantity'] = 'offer_quantity';
+ $columns['offer_amount'] = 'offer_amount';
+ return $columns;
}
- // check for orderby var
- if (!isset($vars['orderby'])) {
- // order by date default
- $vars = array_merge($vars, array(
- 'orderby' => 'post_date',
- 'order' => 'desc'));
- } else {
- if (isset($vars['orderby']) && (($vars['orderby'] == 'date') )) {
- $vars['orderby'] = 'post_date';
+ /*
+ * ADMIN COLUMN - SORTING - ORDERBY
+ * http://scribu.net/wordpress/custom-sortable-columns.html#comment-4732
+ */
+
+ public function woocommerce_offers_list_orderby($vars) {
+
+ if (!is_admin()) {
+ return $vars;
}
- if (isset($vars['orderby']) && (($vars['orderby'] == 'offer_amount') || ($vars['orderby'] == 'offer_price_per') || ($vars['orderby'] == 'offer_quantity') || ($vars['orderby'] == 'offer_amount'))) {
- $vars = array_merge($vars, array(
- 'meta_key' => $vars['orderby'],
- 'orderby' => 'meta_value_num'));
+
+ /**
+ * Below if condition will check for the $vars retrun while they are empty array.
+ * Reason behind adding this Line is Static Fron page will be redirect to Blog page.
+ * Issue's more info : https://github.com/angelleye/offers-for-woocommerce/issues/319
+ * */
+ if (empty($vars)) {
+ return $vars;
}
- if (isset($vars['orderby']) && (($vars['orderby'] == 'offer_name') || ($vars['orderby'] == 'offer_email'))) {
+
+ // check for orderby var
+ if (!isset($vars['orderby'])) {
+ // order by date default
$vars = array_merge($vars, array(
- 'meta_key' => $vars['orderby'],
- 'orderby' => 'meta_value'));
+ 'orderby' => 'post_date',
+ 'order' => 'desc'));
+ } else {
+ if (isset($vars['orderby']) && (($vars['orderby'] == 'date') )) {
+ $vars['orderby'] = 'post_date';
+ }
+ if (isset($vars['orderby']) && (($vars['orderby'] == 'offer_amount') || ($vars['orderby'] == 'offer_price_per') || ($vars['orderby'] == 'offer_quantity') || ($vars['orderby'] == 'offer_amount'))) {
+ $vars = array_merge($vars, array(
+ 'meta_key' => $vars['orderby'],
+ 'orderby' => 'meta_value_num'));
+ }
+ if (isset($vars['orderby']) && (($vars['orderby'] == 'offer_name') || ($vars['orderby'] == 'offer_email'))) {
+ $vars = array_merge($vars, array(
+ 'meta_key' => $vars['orderby'],
+ 'orderby' => 'meta_value'));
+ }
}
+ return $vars;
}
- return $vars;
- }
- /*
- * ADD TO QUERY - PULL IN all except 'trash' when viewing 'all' list
- * @since 0.1.0
- */
+ /*
+ * ADD TO QUERY - PULL IN all except 'trash' when viewing 'all' list
+ * @since 0.1.0
+ */
- public function my_pre_get_posts($query) {
- if (is_admin() && $query->is_main_query() && $query->query['post_type'] == 'woocommerce_offer') {
+ public function my_pre_get_posts($query) {
+ if (is_admin() && $query->is_main_query() && isset($query->query['post_type']) && $query->query['post_type'] == 'woocommerce_offer') {
- $arg_post_type = get_query_var('post_type');
- $arg_post_status = get_query_var('post_status');
- $arg_orderby = get_query_var('orderby');
+ $arg_post_type = get_query_var('post_type');
+ $arg_post_status = get_query_var('post_status');
+ $arg_orderby = get_query_var('orderby');
- if (!$arg_post_status && $arg_post_type == 'woocommerce_offer') {
- $query->set('post_status', array('publish', 'accepted-offer', 'countered-offer', 'buyercountered-offer', 'declined-offer', 'completed-offer', 'on-hold-offer'));
- if (!$arg_orderby) {
- $query->set('orderby', 'post_date');
- $query->set('order', 'desc');
+ if (!$arg_post_status && $arg_post_type == 'woocommerce_offer') {
+ $query->set('post_status', array('publish', 'accepted-offer', 'countered-offer', 'buyercountered-offer', 'declined-offer', 'completed-offer', 'on-hold-offer'));
+ if (!$arg_orderby) {
+ $query->set('orderby', 'post_date');
+ $query->set('order', 'desc');
+ }
}
}
}
- }
- /**
- * Join posts and postmeta tables
- * @since 1.0.1
- */
- function aeofwc_search_join($join) {
- global $wpdb, $screen, $wp;
+ /**
+ * Join posts and postmeta tables
+ * @since 1.0.1
+ */
+ function aeofwc_search_join($join) {
+ global $wpdb, $screen, $wp;
- $screen = get_current_screen();
+ $screen = get_current_screen();
- if (is_search() && $screen->post_type == 'woocommerce_offer') {
+ if (is_search() && !empty($screen->post_type) && $screen->post_type == 'woocommerce_offer') {
- $found_blank_s = (isset($_GET['s']) && isset($_GET['orderby'])) ? TRUE : FALSE;
- if ($found_blank_s) {
- $current_url = add_query_arg($wp->query_string, '', home_url($wp->request));
- $current_url = esc_url_raw($current_url);
- $redirect_url = str_replace("&s=&", "&", $current_url);
- wp_redirect($redirect_url);
+ $found_blank_s = (isset($_GET['s']) && isset($_GET['orderby'])) ? TRUE : FALSE;
+ if ($found_blank_s) {
+ $current_url = add_query_arg($wp->query_string, '', home_url($wp->request));
+ $current_url = esc_url_raw($current_url);
+ $redirect_url = str_replace("&s=&", "&", $current_url);
+ wp_redirect($redirect_url);
+ }
+ $join .= 'LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
- $join .= 'LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
+
+ return $join;
}
- return $join;
- }
+ /**
+ * Modify the search query with posts_where
+ * @since 1.0.1
+ */
+ function aeofwc_search_where($where) {
+ global $pagenow, $wpdb;
- /**
- * Modify the search query with posts_where
- * @since 1.0.1
- */
- function aeofwc_search_where($where) {
- global $pagenow, $wpdb;
+ require_once(ABSPATH . 'wp-admin/includes/screen.php');
+ $screen = get_current_screen();
- require_once(ABSPATH . 'wp-admin/includes/screen.php');
- $screen = get_current_screen();
+ if (is_search() && !empty($screen->post_type) && $screen->post_type == 'woocommerce_offer') {
+ $where = preg_replace(
+ "/\(\s*" . $wpdb->posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", "(" . $wpdb->posts . ".post_title LIKE $1) OR (" . $wpdb->postmeta . ".meta_value LIKE $1)", $where);
+ }
- if (is_search() && $screen->post_type == 'woocommerce_offer') {
- $where = preg_replace(
- "/\(\s*" . $wpdb->posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", "(" . $wpdb->posts . ".post_title LIKE $1) OR (" . $wpdb->postmeta . ".meta_value LIKE $1)", $where);
+ return $where;
}
- return $where;
- }
+ /**
+ * Prevent duplicates
+ * @since 1.0.1
+ */
+ function aeofwc_search_distinct($where) {
+ global $wpdb;
- /**
- * Prevent duplicates
- * @since 1.0.1
- */
- function aeofwc_search_distinct($where) {
- global $wpdb;
+ $screen = get_current_screen();
- $screen = get_current_screen();
+ if (is_search() && !empty($screen->post_type) && $screen->post_type == 'woocommerce_offer') {
+ return "DISTINCT";
+ }
- if (is_search() && $screen->post_type == 'woocommerce_offer') {
- return "DISTINCT";
+ return $where;
}
- return $where;
- }
-
- /**
- * Filter the "quick edit" action links for CPT edit list view
- * @since 0.1.0
- */
- public function remove_quick_edit($actions) {
- global $post;
- if ($post && $post->post_type == 'woocommerce_offer') {
- unset($actions['inline hide-if-no-js']);
- unset($actions['edit']);
- unset($actions['view']);
-
- if ($post->post_status == 'accepted-offer') {
- $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
- $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
- }
- if ($post->post_status == 'countered-offer') {
- $actions['counter-offer-link'] = '' . __('Manage Offer') . ' ';
- $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
- } elseif ($post->post_status == 'declined-offer') {
- $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
- } elseif ($post->post_status == 'on-hold-offer') {
- $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
- $actions['accept-offer-link'] = '' . __('Accept', 'offers-for-woocommerce') . ' ';
- $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
- } elseif ($post->post_status == 'expired-offer') {
- $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
- } elseif ($post->post_status == 'completed-offer') {
- unset($actions['trash']);
- } elseif ($post->post_status == 'trash') {
-
- } elseif ($post->post_status == 'publish' || $post->post_status == 'buyercountered-offer') {
- $actions['counter-offer-link'] = '' . __('Make Counter Offer', 'offers-for-woocommerce') . ' ';
- $actions['accept-offer-link'] = '' . __('Accept', 'offers-for-woocommerce') . ' ';
- $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
+ /**
+ * Filter the "quick edit" action links for CPT edit list view
+ * @since 0.1.0
+ */
+ public function remove_quick_edit($actions) {
+ global $post;
+ if ($post && $post->post_type == 'woocommerce_offer') {
+ unset($actions['inline hide-if-no-js']);
+ unset($actions['edit']);
+ unset($actions['view']);
+
+ if ($post->post_status == 'accepted-offer') {
+ $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
+ $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
+ }
+ if ($post->post_status == 'countered-offer') {
+ $actions['counter-offer-link'] = '' . __('Manage Offer') . ' ';
+ $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
+ } elseif ($post->post_status == 'declined-offer') {
+ $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
+ } elseif ($post->post_status == 'on-hold-offer') {
+ $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
+ $actions['accept-offer-link'] = '' . __('Accept', 'offers-for-woocommerce') . ' ';
+ $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
+ } elseif ($post->post_status == 'expired-offer') {
+ $actions['counter-offer-link'] = '' . __('Manage Offer', 'offers-for-woocommerce') . ' ';
+ } elseif ($post->post_status == 'completed-offer') {
+ unset($actions['trash']);
+ } elseif ($post->post_status == 'trash') {
+
+ } elseif ($post->post_status == 'publish' || $post->post_status == 'buyercountered-offer') {
+ $actions['counter-offer-link'] = '' . __('Make Counter Offer', 'offers-for-woocommerce') . ' ';
+ $actions['accept-offer-link'] = '' . __('Accept', 'offers-for-woocommerce') . ' ';
+ $actions['decline-offer-link'] = '' . __('Decline', 'offers-for-woocommerce') . ' ';
+ }
}
+ return $actions;
}
- return $actions;
- }
- /**
- * Register custom post status type -- Accepted Offer
- * @since 0.1.0
- */
- public function my_custom_post_status_accepted() {
- $args = array(
- 'label' => _x('accepted-offer', __('Accepted Offer', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('Accepted (%s)', 'offers-for-woocommerce'), __('Accepted (%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('accepted-offer', $args);
- }
+ /**
+ * Register custom post status type -- Accepted Offer
+ * @since 0.1.0
+ */
+ public function my_custom_post_status_accepted() {
+ $args = array(
+ 'label' => _x('accepted-offer', __('Accepted Offer', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('Accepted (%s)', 'offers-for-woocommerce'), __('Accepted (%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => true,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('accepted-offer', $args);
+ }
- /**
- * Register custom post status type -- Countered Offer
- * @since 0.1.0
- */
- public function my_custom_post_status_countered() {
- $args = array(
- 'label' => _x('countered-offer', __('Countered Offer', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('Countered (%s)', 'offers-for-woocommerce'), __('Countered (%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('countered-offer', $args);
- }
+ /**
+ * Register custom post status type -- Countered Offer
+ * @since 0.1.0
+ */
+ public function my_custom_post_status_countered() {
+ $args = array(
+ 'label' => _x('countered-offer', __('Countered Offer', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('Countered (%s)', 'offers-for-woocommerce'), __('Countered (%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => true,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('countered-offer', $args);
+ }
- /**
- * Register custom post status type -- Offer On Hold
- * @since 1.0.1
- */
- public function my_custom_post_status_on_hold() {
- $args = array(
- 'label' => _x('on-hold-offer', __('On Hold', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('On Hold (%s)', 'offers-for-woocommerce'), __('On Hold (%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('on-hold-offer', $args);
- }
+ /**
+ * Register custom post status type -- Offer On Hold
+ * @since 1.0.1
+ */
+ public function my_custom_post_status_on_hold() {
+ $args = array(
+ 'label' => _x('on-hold-offer', __('On Hold', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('On Hold (%s)', 'offers-for-woocommerce'), __('On Hold (%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => true,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('on-hold-offer', $args);
+ }
- /**
- * Register custom post status type -- Offer Expired
- * @since 1.0.1
- */
- public function my_custom_post_status_expired() {
- $args = array(
- 'label' => _x('expired-offer', __('Expired', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('Expired (%s)', 'offers-for-woocommerce'), __('Expired(%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => false,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('expired-offer', $args);
- }
-
- /**
- * Register custom post status type -- Buyer Countered Offer
- * @since 0.1.0
- */
- public function my_custom_post_status_buyer_countered() {
- $args = array(
- 'label' => _x('buyercountered-offer', __('Buyer Countered Offer', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('Buyer Countered (%s)', 'offers-for-woocommerce'), __('Buyer Countered (%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('buyercountered-offer', $args);
- }
-
- /**
- * Register custom post status type -- Declined Offer
- * @since 0.1.0
- */
- public function my_custom_post_status_declined() {
- $args = array(
- 'label' => _x('declined-offer', __('Declined Offer', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('Declined (%s)', 'offers-for-woocommerce'), __('Declined (%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('declined-offer', $args);
- }
+ /**
+ * Register custom post status type -- Offer Expired
+ * @since 1.0.1
+ */
+ public function my_custom_post_status_expired() {
+ $args = array(
+ 'label' => _x('expired-offer', __('Expired', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('Expired (%s)', 'offers-for-woocommerce'), __('Expired(%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => false,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('expired-offer', $args);
+ }
- /**
- * Register custom post status type -- Completed Offer
- * @since 0.1.0
- */
- public function my_custom_post_status_completed() {
- $args = array(
- 'label' => _x('completed-offer', __('Completed Offer', 'offers-for-woocommerce')),
- 'label_count' => _n_noop(__('Completed (%s)', 'offers-for-woocommerce'), __('Completed (%s)', 'offers-for-woocommerce')),
- 'public' => true,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'exclude_from_search' => false,
- );
- register_post_status('completed-offer', $args);
- }
+ /**
+ * Register custom post status type -- Buyer Countered Offer
+ * @since 0.1.0
+ */
+ public function my_custom_post_status_buyer_countered() {
+ $args = array(
+ 'label' => _x('buyercountered-offer', __('Buyer Countered Offer', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('Buyer Countered (%s)', 'offers-for-woocommerce'), __('Buyer Countered (%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => true,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('buyercountered-offer', $args);
+ }
- /**
- * Filter - Display post status values on edit list view with customized html elements
- * @since 0.1.0
- */
- public function jc_display_archive_state($states) {
- global $post;
+ /**
+ * Register custom post status type -- Declined Offer
+ * @since 0.1.0
+ */
+ public function my_custom_post_status_declined() {
+ $args = array(
+ 'label' => _x('declined-offer', __('Declined Offer', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('Declined (%s)', 'offers-for-woocommerce'), __('Declined (%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => true,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('declined-offer', $args);
+ }
- $screen = get_current_screen();
+ /**
+ * Register custom post status type -- Completed Offer
+ * @since 0.1.0
+ */
+ public function my_custom_post_status_completed() {
+ $args = array(
+ 'label' => _x('completed-offer', __('Completed Offer', 'offers-for-woocommerce')),
+ 'label_count' => _n_noop(__('Completed (%s)', 'offers-for-woocommerce'), __('Completed (%s)', 'offers-for-woocommerce')),
+ 'public' => true,
+ 'show_in_admin_all_list' => true,
+ 'show_in_admin_status_list' => true,
+ 'exclude_from_search' => false,
+ );
+ register_post_status('completed-offer', $args);
+ }
- if (!empty($screen) && $screen->post_type == 'woocommerce_offer') {
- if ($post->post_status == 'accepted-offer') {
- $states = array('' . __('Accepted', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'countered-offer') {
- $states = array('' . __('Countered', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'buyercountered-offer') {
- $states = array('' . __('Buyer Countered', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'publish') {
- $states = array('' . __('Pending', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'trash') {
- $states = array('' . __('Trashed', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'completed-offer') {
- $states = array('' . __('Completed', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'declined-offer') {
- $states = array('' . __('Declined', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'on-hold-offer') {
- $states = array('' . __('On Hold', 'offers-for-woocommerce') . '
');
- } elseif ($post->post_status == 'expired-offer') {
- $states = array('' . __('Expired', 'offers-for-woocommerce') . '
');
- } else {
- $states = array('' . ucwords($post->post_status) . '
');
- }
+ /**
+ * Filter - Display post status values on edit list view with customized html elements
+ * @since 0.1.0
+ */
+ public function jc_display_archive_state($states) {
+ global $post;
+
+ $screen = get_current_screen();
+
+ if (!empty($screen) && !empty($screen->post_type) && $screen->post_type == 'woocommerce_offer') {
+ if ($post->post_status == 'accepted-offer') {
+ $states = array('' . __('Accepted', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'countered-offer') {
+ $states = array('' . __('Countered', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'buyercountered-offer') {
+ $states = array('' . __('Buyer Countered', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'publish') {
+ $states = array('' . __('Pending', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'trash') {
+ $states = array('' . __('Trashed', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'completed-offer') {
+ $states = array('' . __('Completed', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'declined-offer') {
+ $states = array('' . __('Declined', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'on-hold-offer') {
+ $states = array('' . __('On Hold', 'offers-for-woocommerce') . '
');
+ } elseif ($post->post_status == 'expired-offer') {
+ $states = array('' . __('Expired', 'offers-for-woocommerce') . '
');
+ } else {
+ $states = array('' . ucwords($post->post_status) . '
');
+ }
- if (!empty($states)) {
- $state_count = count($states);
- $i = 0;
- echo '';
- foreach ($states as $state) {
- ++$i;
- ( $i == $state_count ) ? $sep = '' : $sep = ', ';
- echo "$state$sep ";
+ if (!empty($states)) {
+ $state_count = count($states);
+ $i = 0;
+ echo '';
+ foreach ($states as $state) {
+ ++$i;
+ ( $i == $state_count ) ? $sep = '' : $sep = ', ';
+ echo "$state$sep ";
+ }
}
+ return array();
+ } else {
+ return $states;
}
- return;
- } else {
- return $states;
- }
- }
-
- /**
- * Filter - Relabel display of post type "publish" for our CPT on edit list view
- * @since 0.1.0
- */
- public function translate_published_post_label($screen) {
- if ($screen->post_type == 'woocommerce_offer') {
- add_filter('gettext', array($this, 'my_get_translated_text_publish'));
- add_filter('ngettext', array($this, 'my_get_translated_text_publish'));
}
/**
- * Auto-Expire offers with expire date past
- * @since 1.0.1
+ * Filter - Relabel display of post type "publish" for our CPT on edit list view
+ * @since 0.1.0
*/
- if ("edit-woocommerce_offer" == $screen->id) {
- global $wpdb;
+ public function translate_published_post_label($screen) {
+ if (!empty($screen->post_type) && $screen->post_type == 'woocommerce_offer') {
+ add_filter('gettext', array($this, 'my_get_translated_text_publish'));
+ add_filter('ngettext', array($this, 'my_get_translated_text_publish'));
+ }
- $target_now_date = date("Y-m-d H:i:s", current_time('timestamp', 0));
-
- $expired_offers = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE `meta_key` = '%s' AND `meta_value` <> ''", 'offer_expiration_date'), 'ARRAY_A');
- if (($expired_offers) && !empty($expired_offers)) {
- foreach ($expired_offers as $v) {
- $offer_expire_date_formatted = date("Y-m-d 23:59:59", strtotime($v['meta_value']));
- if ($offer_expire_date_formatted <= $target_now_date) {
- $post_status = get_post_status($v['post_id']);
- if ($post_status && $post_status != 'trash') {
- $target_post = array(
- 'ID' => $v['post_id'],
- 'post_status' => 'expired-offer'
- );
- wp_update_post($target_post);
+ /**
+ * Auto-Expire offers with expire date past
+ * @since 1.0.1
+ */
+ if ("edit-woocommerce_offer" == $screen->id) {
+ global $wpdb;
+
+ $target_now_date = date("Y-m-d H:i:s", current_time('timestamp', 0));
+
+ $expired_offers = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE `meta_key` = '%s' AND `meta_value` <> ''", 'offer_expiration_date'), 'ARRAY_A');
+ if (($expired_offers) && !empty($expired_offers)) {
+ foreach ($expired_offers as $v) {
+ $offer_expire_date_formatted = date("Y-m-d 23:59:59", strtotime($v['meta_value']));
+ if ($offer_expire_date_formatted <= $target_now_date) {
+ $post_status = get_post_status($v['post_id']);
+ if ($post_status && $post_status != 'trash') {
+ $target_post = array(
+ 'ID' => $v['post_id'],
+ 'post_status' => 'expired-offer'
+ );
+ wp_update_post($target_post);
+ }
}
}
}
}
}
- }
- /**
- * Translate "Published" language to "Pending"
- * @since 0.1.0
- */
- public function my_get_translated_text_publish($translated) {
- $translated = str_ireplace('Published', 'Pending', $translated);
- return $translated;
- }
+ /**
+ * Translate "Published" language to "Pending"
+ * @since 0.1.0
+ */
+ public function my_get_translated_text_publish($translated) {
+ $translated = str_ireplace('Published', 'Pending', $translated);
+ return $translated;
+ }
- /**
- * Filter - Unset the "edit" option for edit list view
- * @since 0.1.0
- */
- public function my_custom_bulk_actions($actions) {
- unset($actions['edit']);
- return $actions;
- }
+ /**
+ * Filter - Unset the "edit" option for edit list view
+ * @since 0.1.0
+ */
+ public function my_custom_bulk_actions($actions) {
+ unset($actions['edit']);
+ return $actions;
+ }
- /**
- * Action - Add meta box - "Offer Comments"
- * @since 0.1.0
- */
- public function add_meta_box_offer_comments() {
- $screens = array('woocommerce_offer');
- foreach ($screens as $screen) {
- add_meta_box(
- 'section_id_offer_comments', __('Offer Activity Log', 'offers-for-woocommerce'), array($this, 'add_meta_box_offer_comments_callback'), $screen, 'side', 'default'
- );
+ /**
+ * Action - Add meta box - "Offer Comments"
+ * @since 0.1.0
+ */
+ public function add_meta_box_offer_comments() {
+ $screens = array('woocommerce_offer');
+ foreach ($screens as $screen) {
+ add_meta_box(
+ 'section_id_offer_comments', apply_filters('aeofw_offer_activity_log_heading_label', __('Offer Activity Log', 'offers-for-woocommerce')), array($this, 'add_meta_box_offer_comments_callback'), $screen, 'side', 'default'
+ );
+ }
}
- }
- /**
- * Callback - Action - Add meta box - "Offer Comments"
- * Output hmtl for "Offer Comments" meta box
- * @since 0.1.0
- * @param WP_Post $post The object for the current post/page
- */
- public function add_meta_box_offer_comments_callback($post) {
- global $wpdb;
+ /**
+ * Callback - Action - Add meta box - "Offer Comments"
+ * Output hmtl for "Offer Comments" meta box
+ * @since 0.1.0
+ * @param WP_Post $post The object for the current post/page
+ */
+ public function add_meta_box_offer_comments_callback($post) {
+ global $wpdb;
- $query = $wpdb->prepare("SELECT * FROM $wpdb->commentmeta INNER JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE $wpdb->commentmeta.meta_value = '%d' ORDER BY comment_date desc", $post->ID);
- $offer_comments = $wpdb->get_results($query);
+ $query = $wpdb->prepare("SELECT * FROM $wpdb->commentmeta INNER JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE $wpdb->commentmeta.meta_value = '%d' ORDER BY comment_date desc", $post->ID);
+ $offer_comments = $wpdb->get_results($query);
- /*
- * Output html for Offer Comments loop
- */
- include_once('views/meta-panel-comments.php');
- }
+ /*
+ * Output html for Offer Comments loop
+ */
+ include_once('views/meta-panel-comments.php');
+ }
- /**
- * Action - Add meta box - "Offer Summary"
- * @since 0.1.0
- */
- public function add_meta_box_offer_summary() {
- $screen = get_current_screen();
- $screens = array('woocommerce_offer');
- foreach ($screens as $screens_value) {
- add_meta_box(
- 'section_id_offer_summary', ( isset($screen->action) && $screen->action == 'add' ) ? __('Make Offer', 'offers-for-woocommerce') : __('Offer Details', 'offers-for-woocommerce'), array($this, 'add_meta_box_offer_summary_callback'), $screens_value, 'normal', 'high'
- );
+ /**
+ * Action - Add meta box - "Offer Summary"
+ * @since 0.1.0
+ */
+ public function add_meta_box_offer_summary() {
+ $screen = get_current_screen();
+ $screens = array('woocommerce_offer');
+ foreach ($screens as $screens_value) {
+ add_meta_box('section_id_offer_summary', ( isset($screen->action) && $screen->action == 'add' ) ? apply_filters('aeofw_offer_detail_heading_label', __('Make Offer', 'offers-for-woocommerce')) : apply_filters('aeofw_offer_detail_heading_label', __('Offer Details', 'offers-for-woocommerce')), array($this, 'add_meta_box_offer_summary_callback'), $screens_value, 'normal', 'high');
+ }
+ add_meta_box('ofwc_product_offers', apply_filters('aeofw_product_offer_history_heading_label', __('Offer History', 'offers-for-woocommerce')), array($this, 'add_meta_box_product_offers_callback'), 'product', 'normal');
}
- add_meta_box('ofwc_product_offers', __('Offer History', 'offers-for-woocommerce'), array($this, 'add_meta_box_product_offers_callback'), 'product', 'normal');
- }
- /**
- * Callback - Action - Add meta box - "Offer Summary"
- * Output hmtl for "Offer Summary" meta box
- * @since 0.1.0
- * @param WP_Post $post The object for the current post/page
- */
- public function add_meta_box_offer_summary_callback($post) {
- global $post, $wpdb;
+ /**
+ * Callback - Action - Add meta box - "Offer Summary"
+ * Output hmtl for "Offer Summary" meta box
+ * @since 0.1.0
+ * @param WP_Post $post The object for the current post/page
+ */
+ public function add_meta_box_offer_summary_callback($post) {
+ global $post, $wpdb;
- $screen = get_current_screen();
+ $screen = get_current_screen();
- if (isset($screen->action) && $screen->action == 'add') {
+ if (isset($screen->action) && $screen->action == 'add') {
- do_action('angelleye_offer_for_woocommerce_admin_add_offer', $post);
- } else {
- do_action('before_offer_summary_meta_box', $post);
- $offer_currency = get_post_meta($post->ID, 'offer_currency', true);
- if( !empty($offer_currency) ) {
- $currency_symbol = get_woocommerce_currency_symbol($offer_currency);
+ do_action('angelleye_offer_for_woocommerce_admin_add_offer', $post);
} else {
- $offer_currency = get_woocommerce_currency();
- $currency_symbol = get_woocommerce_currency_symbol();
- }
-
- if ($post->ID) {
- $postmeta = get_post_meta($post->ID);
- /* Below line of code fetch the post meta that are set during submit offer */
- $offers_product_addon = get_post_meta($post->ID, 'offers_product_addon', true);
- /* end */
-
- /*
- * Use get_post_meta() to retrieve an existing value
- * from the database and use the value for the form.
- */
- $current_status_value = get_post_status($post->ID);
-
- /*
- * Set default
- */
- if (!isset($current_status_value)) {
- $current_status_value = 'publish';
+ do_action('before_offer_summary_meta_box', $post);
+ $offer_currency = get_post_meta($post->ID, 'offer_currency', true);
+ if (!empty($offer_currency)) {
+ $currency_symbol = get_woocommerce_currency_symbol($offer_currency);
+ } else {
+ $offer_currency = get_woocommerce_currency();
+ $currency_symbol = get_woocommerce_currency_symbol();
}
- // Lookup product data
- $product_id = isset($postmeta['offer_product_id'][0]) ? $postmeta['offer_product_id'][0] : '';
- $product_variant_id = ( isset($postmeta['offer_variation_id'][0]) && $postmeta['offer_variation_id'][0] != '' ) ? $postmeta['offer_variation_id'][0] : '';
- $postmeta['enable_shipping_cost'][0] = ( isset($postmeta['enable_shipping_cost'][0]) && $postmeta['enable_shipping_cost'][0] != '' ) ? $postmeta['enable_shipping_cost'][0] : 0;
- $_product = wc_get_product($product_id);
- if (!is_object($_product)) {
- return;
- }
- if ($_product != false) {
+ if ($post->ID) {
+ $postmeta = get_post_meta($post->ID);
+ /* Below line of code fetch the post meta that are set during submit offer */
+ $offers_product_addon = get_post_meta($post->ID, 'offers_product_addon', true);
+ /* end */
- if ($product_variant_id) {
- $_product_variant = wc_get_product($product_variant_id);
+ /*
+ * Use get_post_meta() to retrieve an existing value
+ * from the database and use the value for the form.
+ */
+ $current_status_value = get_post_status($post->ID);
- $_product_variant_managing_stock = ( $_product_variant->managing_stock() == 'parent' ) ? true : false;
+ /*
+ * Set default
+ */
+ if (!isset($current_status_value)) {
+ $current_status_value = 'publish';
+ }
- $_product_sku = ( $_product_variant->get_sku() ) ? $_product_variant->get_sku() : $_product->get_sku();
- $_product_permalink = $_product_variant->get_permalink();
- $_product_attributes_resulat = $_product_variant->get_variation_attributes();
- foreach ($_product_attributes_resulat as $name => $attribute) {
- $_product_attributes[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': ' . $attribute . ' ';
- }
- $_product_regular_price = ( $_product_variant->get_regular_price() ) ? $_product_variant->get_regular_price() : $_product->get_regular_price();
- $_product_sale_price = ( $_product_variant->get_sale_price() ) ? $_product_variant->get_sale_price() : $_product->get_sale_price();
+ // Lookup product data
+ $product_id = isset($postmeta['offer_product_id'][0]) ? $postmeta['offer_product_id'][0] : '';
+ $product_variant_id = ( isset($postmeta['offer_variation_id'][0]) && $postmeta['offer_variation_id'][0] != '' ) ? $postmeta['offer_variation_id'][0] : '';
+ $postmeta['enable_shipping_cost'][0] = ( isset($postmeta['enable_shipping_cost'][0]) && $postmeta['enable_shipping_cost'][0] != '' ) ? $postmeta['enable_shipping_cost'][0] : 0;
+ $_product = wc_get_product($product_id);
+ if (!is_object($_product)) {
+ return;
+ }
+ if ($_product != false) {
- $_product_managing_stock = ( $_product_variant->managing_stock() ) ? $_product_variant->managing_stock() : $_product->managing_stock();
+ if ($product_variant_id) {
+ $_product_variant = wc_get_product($product_variant_id);
- if (version_compare(WC_VERSION, '3.0', '<')) {
- $_product_stock = ( $_product_variant_managing_stock ) ? $_product_variant->get_total_stock() : $_product->get_total_stock();
- } else {
- $_product_stock = ( $_product_variant_managing_stock ) ? $_product_variant->get_stock_quantity() : $_product->get_stock_quantity();
- }
+ $_product_variant_managing_stock = ( $_product_variant->managing_stock() == 'parent' ) ? true : false;
- $_product_in_stock = ( $_product_variant_managing_stock ) ? $_product_variant->has_enough_stock($postmeta['offer_quantity'][0]) : $_product->has_enough_stock($postmeta['offer_quantity'][0]);
- $_product_backorders_allowed = ( $_product_variant_managing_stock ) ? $_product_variant->backorders_allowed() : $_product->backorders_allowed();
- $_product_backorders_require_notification = ( $_product_variant_managing_stock ) ? $_product_variant->backorders_require_notification() : $_product->backorders_require_notification();
- $_product_formatted_name = $_product_variant->get_formatted_name();
- $_product_image = ( $_product_variant->get_image('shop_thumbnail') ) ? $_product_variant->get_image('shop_thumbnail') : $_product->get_image('shop_thumbnail');
- } else {
- $_product_sku = $_product->get_sku();
- $_product_attributes = array();
- $_product_permalink = $_product->get_permalink();
- $_product_regular_price = $_product->get_regular_price();
- $_product_sale_price = $_product->get_sale_price();
- $_product_managing_stock = $_product->managing_stock();
- $_product_stock = version_compare(WC_VERSION, '3.0', '<') ? $_product->get_total_stock() : $_product->get_stock_quantity();
- $_product_in_stock = $_product->has_enough_stock($postmeta['offer_quantity'][0]);
- $_product_backorders_allowed = $_product->backorders_allowed();
- $_product_backorders_require_notification = $_product->backorders_require_notification();
- $_product_formatted_name = $_product->get_formatted_name();
- $_product_image = $_product->get_image('shop_thumbnail');
-
- // set error message if product not found...
- }
+ $_product_sku = ( $_product_variant->get_sku() ) ? $_product_variant->get_sku() : $_product->get_sku();
+ $_product_permalink = $_product_variant->get_permalink();
+ $_product_attributes_resulat = $_product_variant->get_variation_attributes();
+ foreach ($_product_attributes_resulat as $name => $attribute) {
+ $_product_attributes[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': ' . $attribute . ' ';
+ }
+ $_product_regular_price = ( $_product_variant->get_regular_price() ) ? $_product_variant->get_regular_price() : $_product->get_regular_price();
+ $_product_sale_price = ( $_product_variant->get_sale_price() ) ? $_product_variant->get_sale_price() : $_product->get_sale_price();
- /* Products Addon and Offers Plugin meta check starts */
- $product_addon_id = version_compare(WC_VERSION, '3.0', '<') ? $_product->post->ID : $_product->get_id();
- $_product_addons_data = get_post_meta($product_addon_id, '_product_addons', true);
- /* Products Addon and Offers Plugin meta check end. */
+ $_product_managing_stock = ( $_product_variant->managing_stock() ) ? $_product_variant->managing_stock() : $_product->managing_stock();
- /**
- * Set default expiration date on 'pending' offer expiration date input field
- * @since 1.2.0
- */
- if ($current_status_value == 'publish') {
- // get offers options - general
- $default_expire_date = '';
- $options_general = get_option('offers_for_woocommerce_options_general');
- if (!empty($options_general['general_setting_default_expire_days'])) {
- $current_time = date("Y-m-d H:i:s", current_time('timestamp', 0));
- $default_expire_days = str_replace(",", "", $options_general['general_setting_default_expire_days']);
- $default_expire_date = ($default_expire_days != '') ? date("m/d/Y", strtotime($current_time . ' + ' . $default_expire_days . ' days')) : '';
+ if (version_compare(WC_VERSION, '3.0', '<')) {
+ $_product_stock = ( $_product_variant_managing_stock ) ? $_product_variant->get_total_stock() : $_product->get_total_stock();
+ } else {
+ $_product_stock = ( $_product_variant_managing_stock ) ? $_product_variant->get_stock_quantity() : $_product->get_stock_quantity();
+ }
+
+ $_product_in_stock = ( $_product_variant_managing_stock ) ? $_product_variant->has_enough_stock($postmeta['offer_quantity'][0]) : $_product->has_enough_stock($postmeta['offer_quantity'][0]);
+ $_product_backorders_allowed = ( $_product_variant_managing_stock ) ? $_product_variant->backorders_allowed() : $_product->backorders_allowed();
+ $_product_backorders_require_notification = ( $_product_variant_managing_stock ) ? $_product_variant->backorders_require_notification() : $_product->backorders_require_notification();
+ $_product_formatted_name = $_product_variant->get_formatted_name();
+ $_product_image = ( $_product_variant->get_image('shop_thumbnail') ) ? $_product_variant->get_image('shop_thumbnail') : $_product->get_image('shop_thumbnail');
+ } else {
+ $_product_sku = $_product->get_sku();
+ $_product_attributes = array();
+ $_product_permalink = $_product->get_permalink();
+ $_product_regular_price = $_product->get_regular_price();
+ $_product_sale_price = $_product->get_sale_price();
+ $_product_managing_stock = $_product->managing_stock();
+ $_product_stock = version_compare(WC_VERSION, '3.0', '<') ? $_product->get_total_stock() : $_product->get_stock_quantity();
+ $_product_in_stock = $_product->has_enough_stock($postmeta['offer_quantity'][0]);
+ $_product_backorders_allowed = $_product->backorders_allowed();
+ $_product_backorders_require_notification = $_product->backorders_require_notification();
+ $_product_formatted_name = $_product->get_formatted_name();
+ $_product_image = $_product->get_image('shop_thumbnail');
+
+ // set error message if product not found...
}
- if ($default_expire_date != '') {
- $postmeta['offer_expiration_date'] = array($default_expire_date);
+
+ /* Products Addon and Offers Plugin meta check starts */
+ $product_addon_id = version_compare(WC_VERSION, '3.0', '<') ? $_product->post->ID : $_product->get_id();
+ $_product_addons_data = get_post_meta($product_addon_id, '_product_addons', true);
+ /* Products Addon and Offers Plugin meta check end. */
+
+ /**
+ * Set default expiration date on 'pending' offer expiration date input field
+ * @since 1.2.0
+ */
+ if ($current_status_value == 'publish') {
+ // get offers options - general
+ $default_expire_date = '';
+ $options_general = get_option('offers_for_woocommerce_options_general');
+ if (!empty($options_general['general_setting_default_expire_days'])) {
+ $current_time = date("Y-m-d H:i:s", current_time('timestamp', 0));
+ $default_expire_days = str_replace(",", "", $options_general['general_setting_default_expire_days']);
+ $default_expire_date = ($default_expire_days != '') ? date("m/d/Y", strtotime($current_time . ' + ' . $default_expire_days . ' days')) : '';
+ }
+ if ($default_expire_date != '') {
+ $postmeta['offer_expiration_date'] = array($default_expire_date);
+ }
}
- }
- $offer_inventory_msg = 'Notice: ' . __('Product stock is lower than offer quantity!', 'offers-for-woocommerce');
- $show_offer_inventory_msg = ( $_product_in_stock ) ? FALSE : TRUE;
+ $offer_inventory_msg = 'Notice: ' . __('Product stock is lower than offer quantity!', 'offers-for-woocommerce');
+ $show_offer_inventory_msg = ( $_product_in_stock ) ? FALSE : TRUE;
- $offer_order_meta = array();
- // Check for 'offer_order_id'
- if (isset($postmeta['offer_order_id'][0]) && is_numeric($postmeta['offer_order_id'][0])) {
- $order_id = $postmeta['offer_order_id'][0];
+ $offer_order_meta = array();
+ // Check for 'offer_order_id'
+ if (isset($postmeta['offer_order_id'][0]) && is_numeric($postmeta['offer_order_id'][0])) {
+ $order_id = $postmeta['offer_order_id'][0];
- // Set order meta data array
+ // Set order meta data array
- $offer_order_meta['Order ID'] = '' . '#' . $order_id . ' ';
+ $offer_order_meta['Order ID'] = '' . '#' . $order_id . ' ';
- // Get Order
- $order = new WC_Order($order_id);
- if ($order->post) {
+ // Get Order
+ $order = new WC_Order($order_id);
+ if ($order->post) {
+ $offer_order_meta['Order Date'] = $order->post->post_date;
+ $offer_order_meta['Order Status'] = ucwords($order->get_status());
+ } else {
+ $offer_order_meta['Order ID'] .= 'Notice: ' . __('Order not found; may have been deleted', 'offers-for-woocommerce') . ' ';
+ }
$offer_order_meta['Order Date'] = $order->post->post_date;
$offer_order_meta['Order Status'] = ucwords($order->get_status());
} else {
- $offer_order_meta['Order ID'] .= 'Notice: ' . __('Order not found; may have been deleted', 'offers-for-woocommerce') . ' ';
+ $offer_order_meta['Order ID'] = 'Notice: ' . __('Order not found; may have been deleted', 'offers-for-woocommerce') . ' ';
}
- $offer_order_meta['Order Date'] = $order->post->post_date;
- $offer_order_meta['Order Status'] = ucwords($order->get_status());
- } else {
- $offer_order_meta['Order ID'] = 'Notice: ' . __('Order not found; may have been deleted', 'offers-for-woocommerce') . ' ';
- }
- // set author_data
- $author_data = get_userdata($post->post_author);
+ // set author_data
+ $author_data = get_userdata($post->post_author);
- // set author offer counts
- $author_counts = array();
- if ($author_data) {
- // count offers by author id
+ // set author offer counts
+ $author_counts = array();
+ if ($author_data) {
+ // count offers by author id
- $post_type = 'woocommerce_offer';
+ $post_type = 'woocommerce_offer';
- $args = array($post_type, 'trash', $post->post_author);
- $count_all = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status != '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'trash', $post->post_author);
+ $count_all = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status != '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'publish', $post->post_author);
- $count_pending = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'publish', $post->post_author);
+ $count_pending = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'accepted-offer', $post->post_author);
- $count_accepted = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'accepted-offer', $post->post_author);
+ $count_accepted = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'countered-offer', $post->post_author);
- $count_countered = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'countered-offer', $post->post_author);
+ $count_countered = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'buyercountered-offer', $post->post_author);
- $count_buyer_countered = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'buyercountered-offer', $post->post_author);
+ $count_buyer_countered = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'declined-offer', $post->post_author);
- $count_declined = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'declined-offer', $post->post_author);
+ $count_declined = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'completed-offer', $post->post_author);
- $count_completed = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'completed-offer', $post->post_author);
+ $count_completed = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'on-hold-offer', $post->post_author);
- $count_on_hold = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'on-hold-offer', $post->post_author);
+ $count_on_hold = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $args = array($post_type, 'expired-offer', $post->post_author);
- $count_expired = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
+ $args = array($post_type, 'expired-offer', $post->post_author);
+ $count_expired = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = '%s' AND post_status = '%s' AND post_author = '%s'", $args));
- $author_counts['all'] = apply_filters('get_usernumposts', $count_all, $post->post_author);
- $author_counts['pending'] = apply_filters('get_usernumposts', $count_pending, $post->post_author);
- $author_counts['accepted'] = apply_filters('get_usernumposts', $count_accepted, $post->post_author);
- $author_counts['countered'] = apply_filters('get_usernumposts', $count_countered, $post->post_author);
- $author_counts['buyercountered'] = apply_filters('get_usernumposts', $count_buyer_countered, $post->post_author);
- $author_counts['declined'] = apply_filters('get_usernumposts', $count_declined, $post->post_author);
- $author_counts['completed'] = apply_filters('get_usernumposts', $count_completed, $post->post_author);
- $author_counts['on_hold'] = apply_filters('get_usernumposts', $count_on_hold, $post->post_author);
- $author_counts['expired'] = apply_filters('get_usernumposts', $count_expired, $post->post_author);
+ $author_counts['all'] = apply_filters('get_usernumposts', $count_all, $post->post_author);
+ $author_counts['pending'] = apply_filters('get_usernumposts', $count_pending, $post->post_author);
+ $author_counts['accepted'] = apply_filters('get_usernumposts', $count_accepted, $post->post_author);
+ $author_counts['countered'] = apply_filters('get_usernumposts', $count_countered, $post->post_author);
+ $author_counts['buyercountered'] = apply_filters('get_usernumposts', $count_buyer_countered, $post->post_author);
+ $author_counts['declined'] = apply_filters('get_usernumposts', $count_declined, $post->post_author);
+ $author_counts['completed'] = apply_filters('get_usernumposts', $count_completed, $post->post_author);
+ $author_counts['on_hold'] = apply_filters('get_usernumposts', $count_on_hold, $post->post_author);
+ $author_counts['expired'] = apply_filters('get_usernumposts', $count_expired, $post->post_author);
- $author_data->offer_counts = $author_counts;
- }
+ $author_data->offer_counts = $author_counts;
+ }
- $query_counter_offers_history = $wpdb->prepare("SELECT * FROM $wpdb->commentmeta INNER JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE $wpdb->commentmeta.meta_value = '%d' AND $wpdb->comments.comment_type = 'offers-history' ORDER BY comment_date ASC", $post->ID);
- $query_counter_offers_history_result = $wpdb->get_results($query_counter_offers_history);
- } else {
- wp_die('ERROR : ' . __('Product not found for this offer.', 'offers-for-woocommerce'));
+ $query_counter_offers_history = $wpdb->prepare("SELECT * FROM $wpdb->commentmeta INNER JOIN $wpdb->comments ON $wpdb->commentmeta.comment_id = $wpdb->comments.comment_ID WHERE $wpdb->commentmeta.meta_value = '%d' AND $wpdb->comments.comment_type = 'offers-history' ORDER BY comment_date ASC", $post->ID);
+ $query_counter_offers_history_result = $wpdb->get_results($query_counter_offers_history);
+ } else {
+ wp_die('ERROR : ' . __('Product not found for this offer.', 'offers-for-woocommerce'));
+ }
+ /**
+ * Output html for Offer Comments loop
+ */
+ $is_anonymous_communication_enable = $this->ofw_is_anonymous_communication_enable();
+ $_product_regular_price = angelleye_ofw_get_product_price_multi_currency($_product_regular_price, $offer_currency);
+ $_product_sale_price = angelleye_ofw_get_product_price_multi_currency($_product_sale_price, $offer_currency);
+ include_once('views/meta-panel-summary.php');
}
- /**
- * Output html for Offer Comments loop
- */
- $is_anonymous_communication_enable = $this->ofw_is_anonymous_communication_enable();
- $_product_regular_price = angelleye_ofw_get_product_price_multi_currency($_product_regular_price, $offer_currency);
- $_product_sale_price = angelleye_ofw_get_product_price_multi_currency($_product_sale_price, $offer_currency);
- include_once('views/meta-panel-summary.php');
- }
-
- do_action('after_offer_summary_meta_box', $post);
- }
- }
- /**
- * Action - Add meta box - "Add Offer Note"
- * @since 0.1.0
- */
- public function add_meta_box_offer_addnote() {
- $screens = array('woocommerce_offer');
- foreach ($screens as $screen) {
- add_meta_box(
- 'section_id_offer_addnote', __('Add Offer Note', 'offers-for-woocommerce'), array($this, 'add_meta_box_offer_addnote_callback'), $screen, 'side', 'low'
- );
+ do_action('after_offer_summary_meta_box', $post);
+ }
}
- }
-
- /**
- * Callback - Action - Add meta box - "Add Offer Note"
- * Output hmtl for "Add Offer Note" meta box
- * @since 0.1.0
- * @param WP_Post $post The object for the current post/page
- */
- public function add_meta_box_offer_addnote_callback($post) {
- /*
- * Output html for Offer Add Note form
- */
- include_once('views/meta-panel-add-note.php');
- }
- /**
- * When the post is saved, saves our custom data
- * @since 0.1.0
- * @param int $post_id The ID of the post being saved
- */
- public function myplugin_save_meta_box_data($post_id) {
- /*
- * We need to verify this came from our screen and with proper authorization,
- * because the save_post action can be triggered at other times.
+ /**
+ * Action - Add meta box - "Add Offer Note"
+ * @since 0.1.0
*/
-
- // If this is an autosave, our form has not been submitted, so we don't want to do anything
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return;
+ public function add_meta_box_offer_addnote() {
+ $screens = array('woocommerce_offer');
+ foreach ($screens as $screen) {
+ add_meta_box(
+ 'section_id_offer_addnote', apply_filters('aeofw_offer_add_note_heading_label', __('Add Offer Note', 'offers-for-woocommerce')), array($this, 'add_meta_box_offer_addnote_callback'), $screen, 'side', 'low'
+ );
+ }
}
- // Check if our nonce is set
- if (!isset($_POST['woocommerce_offer_summary_metabox_noncename'])) {
- return;
+ /**
+ * Callback - Action - Add meta box - "Add Offer Note"
+ * Output hmtl for "Add Offer Note" meta box
+ * @since 0.1.0
+ * @param WP_Post $post The object for the current post/page
+ */
+ public function add_meta_box_offer_addnote_callback($post) {
+ /*
+ * Output html for Offer Add Note form
+ */
+ include_once('views/meta-panel-add-note.php');
}
- // Verify that the nonce is valid
- if (!wp_verify_nonce($_POST['woocommerce_offer_summary_metabox_noncename'], 'woocommerce_offer' . $post_id)) {
- return;
- }
+ /**
+ * When the post is saved, saves our custom data
+ * @since 0.1.0
+ * @param int $post_id The ID of the post being saved
+ */
+ public function myplugin_save_meta_box_data($post_id) {
+ /*
+ * We need to verify this came from our screen and with proper authorization,
+ * because the save_post action can be triggered at other times.
+ */
- // Check the user's permissions
- //$user = wp_get_current_user();
- //$allowed_roles = array('vendor', 'administrator', 'shop_manager');
- if (isset($_POST['post_type']) && 'woocommerce_offer' == $_POST['post_type']) {
- if (!current_user_can('edit_page', $post_id) || !current_user_can('edit_woocommerce_offers')) {
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
- }
- do_action('angelleye_ofw_before_offer_action', $post_id, wc_clean($_POST));
- /*
- * OK, its safe for us to save the data now
- */
+ // Check if our nonce is set
+ if (!isset($_POST['woocommerce_offer_summary_metabox_noncename'])) {
+ return;
+ }
- // Save 'final offer' post meta
- $offer_final_offer = (!empty($_POST['offer_final_offer']) && $_POST['offer_final_offer'] == '1') ? '1' : '0';
- update_post_meta($post_id, 'offer_final_offer', $offer_final_offer);
+ // Verify that the nonce is valid
+ if (!wp_verify_nonce($_POST['woocommerce_offer_summary_metabox_noncename'], 'woocommerce_offer' . $post_id)) {
+ return;
+ }
- // Save 'offer_expiration_date' post meta
- $offer_expire_date = !empty($_POST['offer_expiration_date_hidden']) ? wc_clean($_POST['offer_expiration_date_hidden']) : '';
- $offer_expiration_date_formatted = !empty($offer_expire_date) ? date("Y-m-d 23:59:59", strtotime($offer_expire_date)) : '';
+ // Check the user's permissions
+ //$user = wp_get_current_user();
+ //$allowed_roles = array('vendor', 'administrator', 'shop_manager');
+ if (isset($_POST['post_type']) && 'woocommerce_offer' == $_POST['post_type']) {
+ if (!current_user_can('edit_page', $post_id) || !current_user_can('edit_woocommerce_offers')) {
+ return;
+ }
+ }
+ do_action('angelleye_ofw_before_offer_action', $post_id, wc_clean($_POST));
- update_post_meta($post_id, 'offer_expiration_date', $offer_expiration_date_formatted);
+ /*
+ * OK, its safe for us to save the data now
+ */
- // Get current data for Offer after saved
- $post_data = get_post($post_id);
- // Filter Post Status Label
- $post_status_text = (strtolower($post_data->post_status) == 'publish') ? 'Pending' : $post_data->post_status;
- $post_status_text = ucwords(str_replace("-", " ", str_replace("offer", " ", strtolower($post_status_text))));
+ // Save 'final offer' post meta
+ $offer_final_offer = (!empty($_POST['offer_final_offer']) && $_POST['offer_final_offer'] == '1') ? '1' : '0';
+ update_post_meta($post_id, 'offer_final_offer', $offer_final_offer);
- // set update notes
- $offer_notes = !empty($_POST['angelleye_woocommerce_offer_status_notes']) ? wc_clean(wp_slash($_POST['angelleye_woocommerce_offer_status_notes'])) : '';
+ // Save 'offer_expiration_date' post meta
+ $offer_expire_date = !empty($_POST['offer_expiration_date_hidden']) ? wc_clean($_POST['offer_expiration_date_hidden']) : '';
+ $offer_expiration_date_formatted = !empty($offer_expire_date) ? date("Y-m-d H:i", strtotime($offer_expire_date)) : '';
- $product_qty = !empty($_POST['offer_quantity']) ? wc_clean($_POST['offer_quantity']) : '';
- $product_price_per = !empty($_POST['offer_price_per']) ? self::ofwc_format_localized_price(wc_clean($_POST['offer_price_per'])) : '';
- $enable_shipping_cost = (isset($_POST['enable_shipping_cost']) && $_POST['enable_shipping_cost'] == 1) ? 1 : 0;
- $offer_shipping_cost = (isset($_POST['offer_shipping_cost']) && !empty($_POST['offer_shipping_cost']) && $_POST['offer_shipping_cost'] != '0.00') ? self::ofwc_format_localized_price(wc_clean($_POST['offer_shipping_cost'])) : 0.00;
+ update_post_meta($post_id, 'offer_expiration_date', $offer_expiration_date_formatted);
- $product_total = (($product_qty * $product_price_per) + $offer_shipping_cost);
+ // Get current data for Offer after saved
+ $post_data = get_post($post_id);
+ // Filter Post Status Label
+ $post_status_text = (strtolower($post_data->post_status) == 'publish') ? 'Pending' : $post_data->post_status;
+ $post_status_text = ucwords(str_replace("-", " ", str_replace("offer", " ", strtolower($post_status_text))));
- update_post_meta($post_id, 'enable_shipping_cost', $enable_shipping_cost);
- update_post_meta($post_id, 'offer_shipping_cost', $offer_shipping_cost);
+ // set update notes
+ $offer_notes = !empty($_POST['angelleye_woocommerce_offer_status_notes']) ? wc_clean(wp_slash($_POST['angelleye_woocommerce_offer_status_notes'])) : '';
- $product_id = get_post_meta($post_id, 'offer_product_id', true);
- $variant_id = get_post_meta($post_id, 'offer_variation_id', true);
+ $product_qty = !empty($_POST['offer_quantity']) ? wc_clean($_POST['offer_quantity']) : '';
+ $product_price_per = !empty($_POST['offer_price_per']) ? self::ofwc_format_localized_price(wc_clean($_POST['offer_price_per'])) : '';
+ $enable_shipping_cost = (isset($_POST['enable_shipping_cost']) && $_POST['enable_shipping_cost'] == 1) ? 1 : 0;
+ $offer_shipping_cost = (isset($_POST['offer_shipping_cost']) && !empty($_POST['offer_shipping_cost']) && $_POST['offer_shipping_cost'] != '0.00') ? self::ofwc_format_localized_price(wc_clean($_POST['offer_shipping_cost'])) : 0.00;
- $product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
+ $product_total = (($product_qty * $product_price_per) + $offer_shipping_cost);
- $recipient = get_post_meta($post_id, 'offer_email', true);
- $offer_id = $post_id;
- $offer_uid = get_post_meta($post_id, 'offer_uid', true);
- $offer_name = get_post_meta($post_id, 'offer_name', true);
- $offer_email = $recipient;
+ update_post_meta($post_id, 'enable_shipping_cost', $enable_shipping_cost);
+ update_post_meta($post_id, 'offer_shipping_cost', $offer_shipping_cost);
- // if buyercountered-offer previous then use buyer counter values
- $is_offer_buyer_countered_status = (!empty($_POST['post_previous_status']) && $_POST['post_previous_status'] == 'buyercountered-offer' ) ? true : false;
- $product_shipping_cost = $offer_shipping_cost;
- $template_name = '';
+ $product_id = get_post_meta($post_id, 'offer_product_id', true);
+ $variant_id = get_post_meta($post_id, 'offer_variation_id', true);
- // Accept Offer
- if ($post_data->post_status == 'accepted-offer' && !empty($_POST['post_previous_status']) && $_POST['post_previous_status'] != 'accepted-offer') {
- $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'orig_offer_quantity', true);
- $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'orig_offer_price_per', true);
- $product_total = ($product_qty * $product_price_per);
+ $product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
- // Update qty/price/total meta values
- update_post_meta($post_id, 'offer_quantity', $product_qty);
- update_post_meta($post_id, 'offer_price_per', $product_price_per);
- update_post_meta($post_id, 'offer_shipping_cost', $product_shipping_cost);
- update_post_meta($post_id, 'offer_amount', $product_total);
+ $recipient = get_post_meta($post_id, 'offer_email', true);
+ $offer_id = $post_id;
+ $offer_uid = get_post_meta($post_id, 'offer_uid', true);
+ $offer_name = get_post_meta($post_id, 'offer_name', true);
+ $offer_email = $recipient;
- $email_class = 'WC_Accepted_Offer_Email';
- $template_name = 'woocommerce-offer-accepted.php';
- }
+ // if buyercountered-offer previous then use buyer counter values
+ $is_offer_buyer_countered_status = (!empty($_POST['post_previous_status']) && $_POST['post_previous_status'] == 'buyercountered-offer' ) ? true : false;
+ $product_shipping_cost = $offer_shipping_cost;
+ $template_name = '';
- // Offer On Hold
- if ($post_data->post_status == 'on-hold-offer' && !empty($_POST['post_previous_status']) && $_POST['post_previous_status'] != 'on-hold-offer') {
- $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
- $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
+ // Accept Offer
+ if ($post_data->post_status == 'accepted-offer' && !empty($_POST['post_previous_status']) && $_POST['post_previous_status'] != 'accepted-offer') {
+ $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'orig_offer_quantity', true);
+ $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'orig_offer_price_per', true);
+ $product_total = ($product_qty * $product_price_per);
- $email_class = 'WC_Offer_On_Hold_Email';
- $template_name = 'woocommerce-offer-on-hold.php';
- }
+ // Update qty/price/total meta values
+ update_post_meta($post_id, 'offer_quantity', $product_qty);
+ update_post_meta($post_id, 'offer_price_per', $product_price_per);
+ update_post_meta($post_id, 'offer_shipping_cost', $product_shipping_cost);
+ update_post_meta($post_id, 'offer_amount', $product_total);
- // Counter Offer
- if ($post_data->post_status == 'countered-offer') {
- $offer_quantity = !empty($_POST['offer_quantity']) ? wc_clean($_POST['offer_quantity']) : '';
- $offer_price_per = !empty($_POST['offer_price_per']) ? self::ofwc_format_localized_price(wc_clean($_POST['offer_price_per'])) : '';
- $offer_shipping_cost = (!empty($_POST['offer_shipping_cost']) && $_POST['offer_shipping_cost'] != '0.00') ? self::ofwc_format_localized_price(wc_clean($_POST['offer_shipping_cost'])) : 0.00;
- $offer_total = ($offer_quantity * $offer_price_per);
- /**
- * Update Counter Offer post meta values
- */
- update_post_meta($post_id, 'offer_quantity', $offer_quantity);
- update_post_meta($post_id, 'offer_price_per', $offer_price_per);
- update_post_meta($post_id, 'offer_shipping_cost', $offer_shipping_cost);
- update_post_meta($post_id, 'offer_amount', $offer_total);
+ $email_class = 'WC_Accepted_Offer_Email';
+ $template_name = 'woocommerce-offer-accepted.php';
+ }
- $product_qty = $offer_quantity;
- $product_price_per = $offer_price_per;
- $offer_shipping_cost = $offer_shipping_cost;
- $product_total = $offer_total;
+ // Offer On Hold
+ if ($post_data->post_status == 'on-hold-offer' && !empty($_POST['post_previous_status']) && $_POST['post_previous_status'] != 'on-hold-offer') {
+ $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
+ $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
- $email_class = 'WC_Countered_Offer_Email';
- $template_name = 'woocommerce-offer-countered.php';
- }
+ $email_class = 'WC_Offer_On_Hold_Email';
+ $template_name = 'woocommerce-offer-on-hold.php';
+ }
- // Decline Offer
- if ($post_data->post_status == 'declined-offer' && !empty($_POST['post_previous_status']) && $_POST['post_previous_status'] != 'declined-offer') {
- $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
- $coupon_code = !empty($_POST["ofw_coupon_list"]) ? wc_clean($_POST["ofw_coupon_list"]) : '';
- $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
- $product_total = ($product_qty * $product_price_per);
+ // Counter Offer
+ if ($post_data->post_status == 'countered-offer') {
+ $offer_quantity = !empty($_POST['offer_quantity']) ? wc_clean($_POST['offer_quantity']) : '';
+ $offer_price_per = !empty($_POST['offer_price_per']) ? self::ofwc_format_localized_price(wc_clean($_POST['offer_price_per'])) : '';
+ $offer_shipping_cost = (!empty($_POST['offer_shipping_cost']) && $_POST['offer_shipping_cost'] != '0.00') ? self::ofwc_format_localized_price(wc_clean($_POST['offer_shipping_cost'])) : 0.00;
+ $offer_total = ($offer_quantity * $offer_price_per);
+ /**
+ * Update Counter Offer post meta values
+ */
+ update_post_meta($post_id, 'offer_quantity', $offer_quantity);
+ update_post_meta($post_id, 'offer_price_per', $offer_price_per);
+ update_post_meta($post_id, 'offer_shipping_cost', $offer_shipping_cost);
+ update_post_meta($post_id, 'offer_amount', $offer_total);
- $email_class = 'WC_Declined_Offer_Email';
- $template_name = 'woocommerce-offer-declined.php';
- }
+ $product_qty = $offer_quantity;
+ $product_price_per = $offer_price_per;
+ $offer_shipping_cost = $offer_shipping_cost;
+ $product_total = $offer_total;
- // if buyercountered-offer status, update postmeta values for quantity,price,amount
- if ($is_offer_buyer_countered_status) {
- update_post_meta($post_id, 'offer_quantity', $product_qty);
- update_post_meta($post_id, 'offer_price_per', $product_price_per);
- update_post_meta($post_id, 'offer_shipping_cost', $product_shipping_cost);
- update_post_meta($post_id, 'offer_amount', $product_total);
- }
+ $email_class = 'WC_Countered_Offer_Email';
+ $template_name = 'woocommerce-offer-countered.php';
+ }
- $offer_args = array(
- 'recipient' => $recipient,
- 'offer_email' => $recipient,
- 'offer_name' => $offer_name,
- 'offer_id' => $offer_id,
- 'offer_uid' => $offer_uid,
- 'product_id' => $product_id,
- 'product_url' => $product->get_permalink(),
- 'variant_id' => $variant_id,
- 'product' => $product,
- 'product_qty' => $product_qty,
- 'product_price_per' => $product_price_per,
- 'product_shipping_cost' => $product_shipping_cost,
- 'product_total' => $product_total,
- 'offer_notes' => $offer_notes,
- 'final_offer' => $offer_final_offer,
- 'coupon_code' => isset($coupon_code) ? $coupon_code : ''
- );
+ // Decline Offer
+ if ($post_data->post_status == 'declined-offer' && !empty($_POST['post_previous_status']) && $_POST['post_previous_status'] != 'declined-offer') {
+ $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
+ $coupon_code = !empty($_POST["ofw_coupon_list"]) ? wc_clean($_POST["ofw_coupon_list"]) : '';
+ $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
+ $product_total = ($product_qty * $product_price_per);
- $offer_email = apply_filters('angelleye_ofw_pre_email_sent', $offer_email, $offer_args);
+ $email_class = 'WC_Declined_Offer_Email';
+ $template_name = 'woocommerce-offer-declined.php';
+ }
- $offer_args['recipient'] = $offer_email;
+ // if buyercountered-offer status, update postmeta values for quantity,price,amount
+ if ($is_offer_buyer_countered_status) {
+ update_post_meta($post_id, 'offer_quantity', $product_qty);
+ update_post_meta($post_id, 'offer_price_per', $product_price_per);
+ update_post_meta($post_id, 'offer_shipping_cost', $product_shipping_cost);
+ update_post_meta($post_id, 'offer_amount', $product_total);
+ }
- $offer_args['offer_email'] = $offer_email;
+ $offer_args = array(
+ 'recipient' => $recipient,
+ 'offer_email' => $recipient,
+ 'offer_name' => $offer_name,
+ 'offer_id' => $offer_id,
+ 'offer_uid' => $offer_uid,
+ 'product_id' => $product_id,
+ 'product_url' => $product->get_permalink(),
+ 'variant_id' => $variant_id,
+ 'product' => $product,
+ 'product_qty' => $product_qty,
+ 'product_price_per' => $product_price_per,
+ 'product_shipping_cost' => $product_shipping_cost,
+ 'product_total' => $product_total,
+ 'offer_notes' => $offer_notes,
+ 'final_offer' => $offer_final_offer,
+ 'coupon_code' => isset($coupon_code) ? $coupon_code : ''
+ );
- $offer_args['offer_expiration_date'] = ($offer_expire_date) ? $offer_expire_date : FALSE;
+ $offer_email = apply_filters('angelleye_ofw_pre_email_sent', $offer_email, $offer_args);
- if ($variant_id) {
- if ($product->get_sku()) {
- $identifier = $product->get_sku();
- } else {
- $identifier = '#' . $product->get_id();
- }
+ $offer_args['recipient'] = $offer_email;
- $attributes = $product->get_variation_attributes();
- $extra_data = ' – ' . implode(', ', $attributes);
- $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'offers-for-woocommerce'), $identifier, $product->get_title(), $extra_data);
- } else {
- $offer_args['product_title_formatted'] = $product->get_formatted_name();
- }
+ $offer_args['offer_email'] = $offer_email;
- if (isset($email_class) && !empty($email_class)) {
- global $woocommerce;
- // load the WooCommerce Emails
- $emails = $woocommerce->mailer()->get_emails();
+ $offer_args['offer_expiration_date'] = ($offer_expire_date) ? $offer_expire_date : FALSE;
- // select the email we want & trigger it to send
- $new_email = $emails[$email_class];
- $new_email->recipient = $recipient;
+ if ($variant_id) {
+ if ($product->get_sku()) {
+ $identifier = $product->get_sku();
+ } else {
+ $identifier = '#' . $product->get_id();
+ }
- // set plugin slug in email class
- $new_email->plugin_slug = 'offers-for-woocommerce';
+ $attributes = $product->get_variation_attributes();
+ $extra_data = ' – ' . implode(', ', $attributes);
+ $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'offers-for-woocommerce'), $identifier, $product->get_title(), $extra_data);
+ } else {
+ $offer_args['product_title_formatted'] = $product->get_formatted_name();
+ }
- // define email template/path (html)
- $new_email->template_html = $template_name;
- $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/';
+ if (isset($email_class) && !empty($email_class)) {
+ global $woocommerce;
+ // load the WooCommerce Emails
+ $emails = $woocommerce->mailer()->get_emails();
- // define email template/path (plain)
- $new_email->template_plain = $template_name;
- $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/';
+ // select the email we want & trigger it to send
+ $new_email = $emails[$email_class];
+ $new_email->recipient = $recipient;
- $authorization_payment = get_post_meta( $offer_id ,'_authorization_payment_order_id', true);
+ // set plugin slug in email class
+ $new_email->plugin_slug = 'offers-for-woocommerce';
- if( empty($authorization_payment)) {
- $new_email->trigger( $offer_args );
- } elseif ( !empty($authorization_payment) && $post_data->post_status != 'countered-offer') {
- $new_email->trigger( $offer_args );
- }
- }
+ // define email template/path (html)
+ $new_email->template_html = $template_name;
+ $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/';
- // Insert WP comment
- $comment_text = "" . __('Updated - Status:', 'offers-for-woocommerce') . " ";
- $comment_text .= $post_status_text;
+ // define email template/path (plain)
+ $new_email->template_plain = $template_name;
+ $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/';
- // include update notes
- if (isset($offer_notes) && $offer_notes != '') {
- $comment_text .= '' . nl2br($offer_notes);
- }
+ $authorization_payment = get_post_meta($offer_id, '_authorization_payment_order_id', true);
- $data = array(
- 'comment_post_ID' => '',
- 'comment_author' => 'admin',
- 'comment_author_email' => '',
- 'comment_author_url' => '',
- 'comment_content' => $comment_text,
- 'comment_type' => 'offers-history',
- 'comment_parent' => 0,
- 'user_id' => get_current_user_id(),
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
- 'comment_agent' => '',
- 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
- 'comment_approved' => 'post-trashed',
- );
- $new_comment_id = wp_insert_comment($data);
+ if (empty($authorization_payment)) {
+ $new_email->trigger($offer_args);
+ } elseif (!empty($authorization_payment) && $post_data->post_status != 'countered-offer') {
+ $new_email->trigger($offer_args);
+ }
+ }
- // insert comment meta
- if ($new_comment_id) {
- add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true);
- if ($post_data->post_status == 'countered-offer') {
- add_comment_meta($new_comment_id, 'offer_quantity', $offer_quantity, true);
- add_comment_meta($new_comment_id, 'offer_amount', $offer_total, true);
- add_comment_meta($new_comment_id, 'offer_price_per', $offer_price_per, true);
- add_comment_meta($new_comment_id, 'offer_status', '3', true);
+ // Insert WP comment
+ $comment_text = "" . __('Updated - Status:', 'offers-for-woocommerce') . " ";
+ $comment_text .= $post_status_text;
+
+ // include update notes
+ if (isset($offer_notes) && $offer_notes != '') {
+ $comment_text .= '' . nl2br($offer_notes);
}
- }
- do_action('angelleye_ofw_offer_updated', $offer_args, $post_data);
+ $data = array(
+ 'comment_post_ID' => '',
+ 'comment_author' => 'admin',
+ 'comment_author_email' => '',
+ 'comment_author_url' => '',
+ 'comment_content' => $comment_text,
+ 'comment_type' => 'offers-history',
+ 'comment_parent' => 0,
+ 'user_id' => get_current_user_id(),
+ 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
+ 'comment_agent' => '',
+ 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
+ 'comment_approved' => 'post-trashed',
+ );
+ $new_comment_id = wp_insert_comment($data);
- do_action('angelleye_ofw_capture_authorization_payment', $offer_id, $post_data->post_status, true );
- }
+ // insert comment meta
+ if ($new_comment_id) {
+ add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true);
+ if ($post_data->post_status == 'countered-offer') {
+ add_comment_meta($new_comment_id, 'offer_quantity', $offer_quantity, true);
+ add_comment_meta($new_comment_id, 'offer_amount', $offer_total, true);
+ add_comment_meta($new_comment_id, 'offer_price_per', $offer_price_per, true);
+ add_comment_meta($new_comment_id, 'offer_status', '3', true);
+ }
+ }
- /**
- * Initialize the plugin options setup
- * Adds Options, Sections and Fields
- * Registers Settings
- * @since 0.1.0
- * @NOTE: This function is registered with the "admin_init" hook
- */
- public function angelleye_ofwc_intialize_options() {
- /**
- * Add option - 'General Settings'
- */
- //the default options
- $offers_for_woocommerce_options_general = array(
- 'general_setting_enable_make_offer_btn_frontpage' => '1',
- 'general_setting_enable_make_offer_btn_catalog' => '1'
- );
+ do_action('angelleye_ofw_offer_updated', $offer_args, $post_data);
- //check to see if present already
- if (!get_option('offers_for_woocommerce_options_general')) {
- //option not found, add new
- add_option('offers_for_woocommerce_options_general', $offers_for_woocommerce_options_general);
+ do_action('angelleye_ofw_capture_authorization_payment', $offer_id, $post_data->post_status, true);
}
/**
- * Add option - 'Display Settings'
+ * Initialize the plugin options setup
+ * Adds Options, Sections and Fields
+ * Registers Settings
+ * @since 0.1.0
+ * @NOTE: This function is registered with the "admin_init" hook
*/
- //the default options
- $offers_for_woocommerce_options_display = array(
- 'display_setting_make_offer_form_field_offer_total' => '1',
- 'display_setting_make_offer_form_field_offer_company_name' => '1',
- 'display_setting_make_offer_form_field_offer_phone' => '1',
- 'display_setting_make_offer_form_field_offer_notes' => '1',
- 'display_setting_make_offer_button_position_single' => 'default'
- );
-
- //this will check for the setting after version update.
- $admin_button_options_display = get_option('offers_for_woocommerce_options_display');
- if (!isset($admin_button_options_display['display_setting_make_offer_button_position_single'])) {
- update_option('offers_for_woocommerce_options_display', $offers_for_woocommerce_options_display);
- }
+ public function angelleye_ofwc_intialize_options() {
+ /**
+ * Add option - 'General Settings'
+ */
+ //the default options
+ $offers_for_woocommerce_options_general = array(
+ 'general_setting_enable_make_offer_btn_frontpage' => '1',
+ 'general_setting_enable_make_offer_btn_catalog' => '1'
+ );
- //check to see if present already
- if (!get_option('offers_for_woocommerce_options_display')) {
- //option not found, add new
- add_option('offers_for_woocommerce_options_display', $offers_for_woocommerce_options_display);
- }
+ //check to see if present already
+ if (!get_option('offers_for_woocommerce_options_general')) {
+ //option not found, add new
+ add_option('offers_for_woocommerce_options_general', $offers_for_woocommerce_options_general);
+ }
- $angelleye_displaySettingFormFieldPosition = array(
- '3' => 'display_setting_make_offer_form_field_offer_name',
- '4' => 'display_setting_make_offer_form_field_offer_email',
- '5' => 'display_setting_make_offer_form_field_offer_company_name',
- '6' => 'display_setting_make_offer_form_field_offer_phone',
- '7' => 'display_setting_make_offer_form_field_offer_notes',
- '8' => 'display_setting_make_offer_form_field_offer_total'
- );
+ /**
+ * Add option - 'Display Settings'
+ */
+ //the default options
+ $offers_for_woocommerce_options_display = array(
+ 'display_setting_make_offer_form_field_offer_total' => '1',
+ 'display_setting_make_offer_form_field_offer_company_name' => '1',
+ 'display_setting_make_offer_form_field_offer_phone' => '1',
+ 'display_setting_make_offer_form_field_offer_notes' => '1',
+ 'display_setting_make_offer_button_position_single' => 'default'
+ );
- if (!get_option('angelleye_displaySettingFormFieldPosition')) {
- //option not found, add new
- add_option('angelleye_displaySettingFormFieldPosition', $angelleye_displaySettingFormFieldPosition);
- }
+ //this will check for the setting after version update.
+ $admin_button_options_display = get_option('offers_for_woocommerce_options_display');
+ if (!isset($admin_button_options_display['display_setting_make_offer_button_position_single'])) {
+ update_option('offers_for_woocommerce_options_display', $offers_for_woocommerce_options_display);
+ }
+ //check to see if present already
+ if (!get_option('offers_for_woocommerce_options_display')) {
+ //option not found, add new
+ add_option('offers_for_woocommerce_options_display', $offers_for_woocommerce_options_display);
+ }
- /**
- * Register setting - 'General Settings'
- */
- register_setting(
- 'offers_for_woocommerce_options_general', // Option group
- 'offers_for_woocommerce_options_general', // Option name
- '' // Validate
- );
+ $angelleye_displaySettingFormFieldPosition = array(
+ '3' => 'display_setting_make_offer_form_field_offer_name',
+ '4' => 'display_setting_make_offer_form_field_offer_email',
+ '5' => 'display_setting_make_offer_form_field_offer_company_name',
+ '6' => 'display_setting_make_offer_form_field_offer_phone',
+ '7' => 'display_setting_make_offer_form_field_offer_notes',
+ '8' => 'display_setting_make_offer_form_field_offer_total'
+ );
- /**
- * Register setting - 'Display Settings'
- */
- register_setting(
- 'offers_for_woocommerce_options_display', // Option group
- 'offers_for_woocommerce_options_display', // Option name
- '' // Validate
- );
+ if (!get_option('angelleye_displaySettingFormFieldPosition')) {
+ //option not found, add new
+ add_option('angelleye_displaySettingFormFieldPosition', $angelleye_displaySettingFormFieldPosition);
+ }
- /**
- * Add section - 'General Settings'
- */
- add_settings_section(
- 'general_settings', // ID
- '', // Title
- array($this, 'offers_for_woocommerce_options_page_intro_text'), // Callback page intro text
- 'offers_for_woocommerce_general_settings' // Page
- );
- /**
- * Add field - 'General Settings' - 'general_setting_enable_make_offer_btn_frontpage'
- * Enable Make Offer button on home page
- */
- add_settings_field(
- 'general_setting_enable_make_offer_btn_frontpage', // ID
- __('Show on Home Page', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_enable_make_offer_btn_frontpage',
- 'input_required' => FALSE,
- 'description' => __('Check this option to display offer buttons for products on your home page.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Register setting - 'General Settings'
+ */
+ register_setting(
+ 'offers_for_woocommerce_options_general', // Option group
+ 'offers_for_woocommerce_options_general', // Option name
+ '' // Validate
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_enable_make_offer_btn_catalog'
- * Enable Make Offer button on shop page
- */
- add_settings_field(
- 'general_setting_enable_make_offer_btn_catalog', // ID
- __('Show on Shop Page', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_enable_make_offer_btn_catalog',
- 'input_required' => FALSE,
- 'description' => __('Check this option to display offer buttons for products on your shop page.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Register setting - 'Display Settings'
+ */
+ register_setting(
+ 'offers_for_woocommerce_options_display', // Option group
+ 'offers_for_woocommerce_options_display', // Option name
+ '' // Validate
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_enable_offers_by_default'
- * Enable Make Offer button on new products by default
- */
- add_settings_field(
- 'general_setting_enable_offers_by_default', // ID
- __('Enable Offers by Default', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_enable_offers_by_default',
- 'input_required' => FALSE,
- 'description' => __('Check this option to automatically enable offers on all new products by default.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add section - 'General Settings'
+ */
+ add_settings_section(
+ 'general_settings', // ID
+ '', // Title
+ array($this, 'offers_for_woocommerce_options_page_intro_text'), // Callback page intro text
+ 'offers_for_woocommerce_general_settings' // Page
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_limit_offer_quantity_by_stock'
- * Limit Offer Quantity on products with limited stock and no backorders
- */
- add_settings_field(
- 'general_setting_limit_offer_quantity_by_stock', // ID
- __('Limit Offer Quantity at Product Stock Quantity', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_limit_offer_quantity_by_stock',
- 'input_required' => FALSE,
- 'description' => __('Check this option to limit offer quantity at stock quantity on products not allowing backorders.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_enable_make_offer_btn_frontpage'
+ * Enable Make Offer button on home page
+ */
+ add_settings_field(
+ 'general_setting_enable_make_offer_btn_frontpage', // ID
+ __('Show on Home Page', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_enable_make_offer_btn_frontpage',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to display offer buttons for products on your home page.', 'offers-for-woocommerce'),
+ )
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_default_expire_days'
- * Default amount of days out to set expire date
- */
- add_settings_field(
- 'general_setting_default_expire_days', // ID
- __('Default Expiration Date', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_text'), // Callback TEXT input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_default_expire_days',
- 'input_required' => FALSE,
- 'description' => __('The number entered here will be used to automatically set the expiration date that many days in advance while accepting or countering an offer.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_enable_make_offer_btn_catalog'
+ * Enable Make Offer button on shop page
+ */
+ add_settings_field(
+ 'general_setting_enable_make_offer_btn_catalog', // ID
+ __('Show on Shop Page', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_enable_make_offer_btn_catalog',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to display offer buttons for products on your shop page.', 'offers-for-woocommerce'),
+ )
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_enable_offers_only_logged_in_users'
- * Enable Offers For Only Logged-in Users
- */
- add_settings_field(
- 'general_setting_enable_offers_required_logged_in_users', // ID
- __('Require Log In', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback Checkbox input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_enable_offers_only_logged_in_users',
- 'input_required' => FALSE,
- 'description' => __('Check this option to require users to login in order to submit an offer.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_enable_offers_by_default'
+ * Enable Make Offer button on new products by default
+ */
+ add_settings_field(
+ 'general_setting_enable_offers_by_default', // ID
+ __('Enable Offers by Default', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_enable_offers_by_default',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to automatically enable offers on all new products by default.', 'offers-for-woocommerce'),
+ )
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_enable_offers_only_logged_in_users'
- * Enable Offers For Only Logged-in Users
- */
- add_settings_field(
- 'general_setting_enable_offers_only_logged_in_users', // ID
- __('Hide Offers Until Logged In', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback Checkbox input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_enable_offers_hide_untill_logged_in_users',
- 'input_required' => FALSE,
- 'description' => __('Check this option to completely hide the offer buttons unless the user is logged in.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_limit_offer_quantity_by_stock'
+ * Limit Offer Quantity on products with limited stock and no backorders
+ */
+ add_settings_field(
+ 'general_setting_limit_offer_quantity_by_stock', // ID
+ __('Limit Offer Quantity at Product Stock Quantity', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_limit_offer_quantity_by_stock',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to limit offer quantity at stock quantity on products not allowing backorders.', 'offers-for-woocommerce'),
+ )
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_allowed_roles'
- * Enable Offers For Only Specific User Roles
- */
- $editable_roles = get_editable_roles();
- $editable_roles_inputs = array();
- foreach ($editable_roles as $role) {
- array_push($editable_roles_inputs, array('option_label' => $role['name'], 'option_value' => strtolower($role['name']))
+ /**
+ * Add field - 'General Settings' - 'general_setting_default_expire_days'
+ * Default amount of days out to set expire date
+ */
+ add_settings_field(
+ 'general_setting_default_expire_days', // ID
+ __('Default Expiration Date', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_text'), // Callback TEXT input
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_default_expire_days',
+ 'input_required' => FALSE,
+ 'description' => __('The number entered here will be used to automatically set the expiration date that many days in advance while accepting or countering an offer.', 'offers-for-woocommerce'),
+ )
);
- }
- add_settings_field(
- 'general_setting_allowed_roles', // ID
- __('Enable Offers for Only Specific User Roles', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_select'), // Callback SELECT input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_allowed_roles',
- 'input_required' => FALSE,
- 'description' => __('Select the roles you want offers enabled for. Leave blank for all roles enabled.', 'offers-for-woocommerce'),
- 'options' => $editable_roles_inputs,
- 'multiple' => TRUE,
- 'extra_classes' => 'chosen-select'
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_enable_offers_only_logged_in_users'
+ * Enable Offers For Only Logged-in Users
+ */
+ add_settings_field(
+ 'general_setting_enable_offers_required_logged_in_users', // ID
+ __('Require Log In', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback Checkbox input
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_enable_offers_only_logged_in_users',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to require users to login in order to submit an offer.', 'offers-for-woocommerce'),
+ )
+ );
+ /**
+ * Add field - 'General Settings' - 'general_setting_enable_offers_only_logged_in_users'
+ * Enable Offers For Only Logged-in Users
+ */
+ add_settings_field(
+ 'general_setting_enable_offers_only_logged_in_users', // ID
+ __('Hide Offers Until Logged In', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback Checkbox input
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_enable_offers_hide_untill_logged_in_users',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to completely hide the offer buttons unless the user is logged in.', 'offers-for-woocommerce'),
+ )
+ );
- /**
- * Add field - 'General Settings' - 'general_setting_disable_coupon'
- * Disable coupons when checking out with accepted offer
- */
- add_settings_field(
- 'general_setting_disable_coupon', // ID
- __('Disable Coupons', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_disable_coupon',
- 'input_required' => FALSE,
- 'description' => __('Check this option to disable coupons when checking out with an accepted offer included in the shopping cart.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_allowed_roles'
+ * Enable Offers For Only Specific User Roles
+ */
+ $editable_roles = get_editable_roles();
+ $editable_roles_inputs = array();
+ foreach ($editable_roles as $role) {
+ array_push($editable_roles_inputs, array('option_label' => $role['name'], 'option_value' => strtolower($role['name']))
+ );
+ }
+ add_settings_field(
+ 'general_setting_allowed_roles', // ID
+ __('Enable Offers for Only Specific User Roles', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_select'), // Callback SELECT input
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_allowed_roles',
+ 'input_required' => FALSE,
+ 'description' => __('Select the roles you want offers enabled for. Leave blank for all roles enabled.', 'offers-for-woocommerce'),
+ 'options' => $editable_roles_inputs,
+ 'multiple' => TRUE,
+ 'extra_classes' => 'chosen-select'
+ )
+ );
- add_settings_field(
- 'general_setting_enable_anonymous_communication', // ID
- __('Enable Anonymous Communication', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_required' => FALSE,
- 'input_label' => 'general_setting_enable_anonymous_communication',
- 'description' => __('Check this option to hide the contact information for potential buyers while negotiation is going on. This can be useful when working with vendors who would be paying you a commission.', 'offers-for-woocommerce'),
- )
- );
+ /**
+ * Add field - 'General Settings' - 'general_setting_disable_coupon'
+ * Disable coupons when checking out with accepted offer
+ */
+ add_settings_field(
+ 'general_setting_disable_coupon', // ID
+ __('Disable Coupons', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_disable_coupon',
+ 'input_required' => FALSE,
+ 'description' => __('Check this option to disable coupons when checking out with an accepted offer included in the shopping cart.', 'offers-for-woocommerce'),
+ )
+ );
- add_settings_field(
- 'general_setting_show_pending_offer', // ID
- __('Show Pending Offer Details to Buyers', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_required' => FALSE,
- 'input_label' => 'general_setting_show_pending_offer',
- 'description' => __('Check this option to display pending offer(s) on front end.', 'offers-for-woocommerce'),
- )
- );
+ add_settings_field(
+ 'general_setting_enable_anonymous_communication', // ID
+ __('Enable Anonymous Communication', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_required' => FALSE,
+ 'input_label' => 'general_setting_enable_anonymous_communication',
+ 'description' => __('Check this option to hide the contact information for potential buyers while negotiation is going on. This can be useful when working with vendors who would be paying you a commission.', 'offers-for-woocommerce'),
+ )
+ );
+ add_settings_field(
+ 'general_setting_show_pending_offer', // ID
+ __('Show Pending Offer Details to Buyers', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_required' => FALSE,
+ 'input_label' => 'general_setting_show_pending_offer',
+ 'description' => __('Check this option to display pending offer(s) on front end.', 'offers-for-woocommerce'),
+ )
+ );
- add_settings_field(
- 'general_setting_show_highest_current_bid', // ID
- __('Display Highest Offer', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_required' => FALSE,
- 'input_label' => 'general_setting_show_highest_current_bid',
- 'description' => __('Check this option to display the highest current offer on product page for potential buyers to see.', 'offers-for-woocommerce'),
- )
- );
+ add_settings_field(
+ 'general_setting_show_highest_current_bid', // ID
+ __('Display Highest Offer', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_required' => FALSE,
+ 'input_label' => 'general_setting_show_highest_current_bid',
+ 'description' => __('Check this option to display the highest current offer on product page for potential buyers to see.', 'offers-for-woocommerce'),
+ )
+ );
- add_settings_field(
- 'general_setting_admin_disable_email_auto_decline', // ID
- __('Disable Admin Email on Auto Declined Offers', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_required' => FALSE,
- 'input_label' => 'general_setting_admin_disable_email_auto_decline',
- 'description' => __('Disable the email notification for the admin user when offers are automatically declined.', 'offers-for-woocommerce'),
- )
- );
+ add_settings_field(
+ 'general_setting_admin_disable_email_auto_decline', // ID
+ __('Disable Admin Email on Auto Declined Offers', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_required' => FALSE,
+ 'input_label' => 'general_setting_admin_disable_email_auto_decline',
+ 'description' => __('Disable the email notification for the admin user when offers are automatically declined.', 'offers-for-woocommerce'),
+ )
+ );
- add_settings_field(
- 'general_setting_disabled_make_offer_on_product_sale', // ID
- __('Disable for Sale Items', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback TEXT input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'general_setting_disabled_make_offer_on_product_sale',
- 'input_required' => FALSE,
- 'description' => __('Disable the "Make Offer" button for products that are on sale.', 'offers-for-woocommerce'),
- )
- );
+ add_settings_field(
+ 'general_setting_disabled_make_offer_on_product_sale', // ID
+ __('Disable for Sale Items', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback TEXT input
+ 'offers_for_woocommerce_general_settings', // Page
+ 'general_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_general',
+ 'input_label' => 'general_setting_disabled_make_offer_on_product_sale',
+ 'input_required' => FALSE,
+ 'description' => __('Disable the "Make Offer" button for products that are on sale.', 'offers-for-woocommerce'),
+ )
+ );
- add_settings_field(
- 'enable_binding_offer_authorization', // ID
- __('Enable Binding Offers', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback TEXT input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'enable_binding_offer_authorization',
- 'input_required' => FALSE,
- 'description' => __('Provide an option for potential buyers to authorize their offer amount, so that you can process the payment instantly when accepting the offer.', 'offers-for-woocommerce'),
- )
- );
-
- add_settings_field(
- 'enable_make_offer_payment_authorization', // ID
- __('Require Binding Offer', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_checkbox'), // Callback TEXT input
- 'offers_for_woocommerce_general_settings', // Page
- 'general_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_general',
- 'input_label' => 'enable_make_offer_payment_authorization',
- 'input_required' => FALSE,
- 'description' => __('Enable this to require a payment authorization with all offers.', 'offers-for-woocommerce'),
- )
- );
- /**
- * Add section - 'Display Settings'
- */
- add_settings_section(
- 'display_settings', // ID
- '', // Title
- array($this, 'offers_for_woocommerce_options_page_intro_text'), // Callback page intro text
- 'offers_for_woocommerce_display_settings' // Page
- );
+ /**
+ * Add section - 'Display Settings'
+ */
+ add_settings_section(
+ 'display_settings', // ID
+ '', // Title
+ array($this, 'offers_for_woocommerce_options_page_intro_text'), // Callback page intro text
+ 'offers_for_woocommerce_display_settings' // Page
+ );
- /**
- * Add field - 'Display Settings' - 'display_setting_enable_make_offer_form_lightbox'
- * Enable Make Offer button on home page
- */
- add_settings_field(
- 'display_setting_make_offer_form_display_type', // ID
- __('Form Display Type', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_select'), // Callback SELECT input
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_make_offer_form_display_type',
- 'input_required' => FALSE,
- 'description' => __('Depending on your theme, you may wish to display the offer form on a tab within the product page or in a lightbox window on top of the product page.', 'offers-for-woocommerce'),
- 'options' => array(
- array('option_label' => __('Product Tabs (default display)', 'offers-for-woocommerce'), 'option_value' => 'tabs'),
- array('option_label' => __('Lightbox', 'offers-for-woocommerce'), 'option_value' => 'lightbox')
- ))
- );
+ /**
+ * Add field - 'Display Settings' - 'display_setting_enable_make_offer_form_lightbox'
+ * Enable Make Offer button on home page
+ */
+ add_settings_field(
+ 'display_setting_make_offer_form_display_type', // ID
+ __('Form Display Type', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_select'), // Callback SELECT input
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_make_offer_form_display_type',
+ 'input_required' => FALSE,
+ 'description' => __('Depending on your theme, you may wish to display the offer form on a tab within the product page or in a lightbox window on top of the product page.', 'offers-for-woocommerce'),
+ 'options' => array(
+ array('option_label' => __('Product Tabs (default display)', 'offers-for-woocommerce'), 'option_value' => 'tabs'),
+ array('option_label' => __('Lightbox', 'offers-for-woocommerce'), 'option_value' => 'lightbox')
+ ))
+ );
- /**
- * Add field - 'Display Settings' - 'display_setting_make_offer_form_fields'
- * Enable optional form fields on make offer form
- */
- $button_display_position = get_option('angelleye_displaySettingFormFieldPosition');
- $form_fields_options = array(
- array('option_label' => __('Quantity', 'offers-for-woocommerce'), 'option_name' => 'offer_quantity', 'option_disabled' => TRUE, 'option_sequence' => '0'),
- array('option_label' => __('Price Each', 'offers-for-woocommerce'), 'option_name' => 'offer_price_each', 'option_disabled' => TRUE, 'option_sequence' => '0'),
- array('option_label' => __('Your Name', 'offers-for-woocommerce'), 'option_name' => 'offer_name', 'option_disabled' => TRUE, 'option_sequence' => '3'),
- array('option_label' => __('Your Email Address', 'offers-for-woocommerce'), 'option_name' => 'offer_email', 'option_disabled' => TRUE, 'option_sequence' => '4'),
- array('option_label' => __('Company Name', 'offers-for-woocommerce'), 'option_name' => 'offer_company_name', 'option_disabled' => FALSE, 'option_sequence' => '5'),
- array('option_label' => __('Phone Number', 'offers-for-woocommerce'), 'option_name' => 'offer_phone', 'option_disabled' => FALSE, 'option_sequence' => '6'),
- array('option_label' => __('Offer Notes', 'offers-for-woocommerce'), 'option_name' => 'offer_notes', 'option_disabled' => FALSE, 'option_sequence' => '7'),
- array('option_label' => __('Total Offer Amount', 'offers-for-woocommerce'), 'option_name' => 'offer_total', 'option_disabled' => FALSE, 'option_sequence' => '8')
- );
- add_settings_field(
- 'display_setting_make_offer_form_fields', // ID
- __('Form Fields', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_checkbox_group'), // Callback checkbox group
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_make_offer_form_field',
- 'input_required' => FALSE,
- 'description' => __('Check the boxes of the form fields you want to display on the offer form. Quantity, Price Each, Your Name, and Your Email Address are forcefully required fields, while the remaining fields are optionally required via checkbox. You may also drag and drop fields to re-order the way they are displayed on the offer form.', 'offers-for-woocommerce'),
- 'options' => $form_fields_options
- )
- );
+ /**
+ * Add field - 'Display Settings' - 'display_setting_make_offer_form_fields'
+ * Enable optional form fields on make offer form
+ */
+ $button_display_position = get_option('angelleye_displaySettingFormFieldPosition');
+ $form_fields_options = array(
+ array('option_label' => __('Quantity', 'offers-for-woocommerce'), 'option_name' => 'offer_quantity', 'option_disabled' => TRUE, 'option_sequence' => '0'),
+ array('option_label' => __('Price Each', 'offers-for-woocommerce'), 'option_name' => 'offer_price_each', 'option_disabled' => TRUE, 'option_sequence' => '0'),
+ array('option_label' => __('Your Name', 'offers-for-woocommerce'), 'option_name' => 'offer_name', 'option_disabled' => TRUE, 'option_sequence' => '3'),
+ array('option_label' => __('Your Email Address', 'offers-for-woocommerce'), 'option_name' => 'offer_email', 'option_disabled' => TRUE, 'option_sequence' => '4'),
+ array('option_label' => __('Company Name', 'offers-for-woocommerce'), 'option_name' => 'offer_company_name', 'option_disabled' => FALSE, 'option_sequence' => '5'),
+ array('option_label' => __('Phone Number', 'offers-for-woocommerce'), 'option_name' => 'offer_phone', 'option_disabled' => FALSE, 'option_sequence' => '6'),
+ array('option_label' => __('Offer Notes', 'offers-for-woocommerce'), 'option_name' => 'offer_notes', 'option_disabled' => FALSE, 'option_sequence' => '7'),
+ array('option_label' => __('Total Offer Amount', 'offers-for-woocommerce'), 'option_name' => 'offer_total', 'option_disabled' => FALSE, 'option_sequence' => '8')
+ );
+ add_settings_field(
+ 'display_setting_make_offer_form_fields', // ID
+ __('Form Fields', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_checkbox_group'), // Callback checkbox group
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_make_offer_form_field',
+ 'input_required' => FALSE,
+ 'description' => __('Check the boxes of the form fields you want to display on the offer form. Quantity, Price Each, Your Name, and Your Email Address are forcefully required fields, while the remaining fields are optionally required via checkbox. You may also drag and drop fields to re-order the way they are displayed on the offer form.', 'offers-for-woocommerce'),
+ 'options' => $form_fields_options
+ )
+ );
+
+ /**
+ * Add field - 'Display Settings' - 'display_setting_make_offer_button_position_single'
+ * Make Offer Button position
+ */
+ add_settings_field(
+ 'display_setting_make_offer_button_position_single', // ID
+ __('Button Position', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_select'), // Callback SELECT input
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_make_offer_button_position_single',
+ 'input_required' => FALSE,
+ 'description' => __('Use this setting to adjust the location of the \'Make Offer\' button on your product detail page.', 'offers-for-woocommerce'),
+ 'options' => array(
+ array('option_label' => __('After add to cart button (default display)', 'offers-for-woocommerce'), 'option_value' => 'default'),
+ array('option_label' => __('Before add to cart button', 'offers-for-woocommerce'), 'option_value' => 'before_add'),
+ array('option_label' => __('To the right of add to cart button', 'offers-for-woocommerce'), 'option_value' => 'right_of_add'),
+ array('option_label' => __('After product price', 'offers-for-woocommerce'), 'option_value' => 'after_price'),
+ array('option_label' => __('After product tabs', 'offers-for-woocommerce'), 'option_value' => 'after_tabs')
+ ))
+ );
+
+ /**
+ * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_class'
+ * Make Offer Button Class
+ */
+ add_settings_field(
+ 'display_setting_custom_make_offer_btn_class', // ID
+ __('Button Class', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_text'), // Callback TEXT input
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_custom_make_offer_btn_class',
+ 'input_required' => FALSE,
+ 'description' => __('Set a custom CSS class name for the offer button.', 'offers-for-woocommerce'),
+ )
+ );
+
+ /**
+ * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_text'
+ * Make Offer Button Text
+ */
+ add_settings_field(
+ 'display_setting_custom_make_offer_btn_text', // ID
+ __('Button Text', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_text'), // Callback TEXT input
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_custom_make_offer_btn_text',
+ 'input_required' => FALSE,
+ 'description' => __('Set the text you would like to be displayed in the offer button.', 'offers-for-woocommerce'),
+ )
+ );
+
+ /**
+ * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_text_color'
+ * Make Offer Button Text Color
+ */
+ add_settings_field(
+ 'display_setting_custom_make_offer_btn_text_color', // ID
+ __('Button Text Color', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_colorpicker'), // Callback TEXT input
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_custom_make_offer_btn_text_color',
+ 'input_required' => FALSE,
+ 'description' => __('Use the color-picker to choose the font color for the text on your offer buttons.', 'offers-for-woocommerce'),
+ )
+ );
+
+ /**
+ * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_color'
+ * Make Offer Button Text Color
+ */
+ add_settings_field(
+ 'display_setting_custom_make_offer_btn_color', // ID
+ __('Button Color', 'offers-for-woocommerce'), // Title
+ array($this, 'offers_for_woocommerce_options_page_output_input_colorpicker'), // Callback TEXT input
+ 'offers_for_woocommerce_display_settings', // Page
+ 'display_settings', // Section
+ array(
+ 'option_name' => 'offers_for_woocommerce_options_display',
+ 'input_label' => 'display_setting_custom_make_offer_btn_color',
+ 'input_required' => FALSE,
+ 'description' => __('Use the color-picker to choose the background color for your offer buttons.', 'offers-for-woocommerce'),
+ )
+ );
+ }
+
+// END - angelleye_ofwc_intialize_options
/**
- * Add field - 'Display Settings' - 'display_setting_make_offer_button_position_single'
- * Make Offer Button position
+ * Enqueue the colour picker
+ * This is called by function 'enqueue_admin_scripts'
+ * @since 0.1.0
*/
- add_settings_field(
- 'display_setting_make_offer_button_position_single', // ID
- __('Button Position', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_select'), // Callback SELECT input
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_make_offer_button_position_single',
- 'input_required' => FALSE,
- 'description' => __('Use this setting to adjust the location of the \'Make Offer\' button on your product detail page.', 'offers-for-woocommerce'),
- 'options' => array(
- array('option_label' => __('After add to cart button (default display)', 'offers-for-woocommerce'), 'option_value' => 'default'),
- array('option_label' => __('Before add to cart button', 'offers-for-woocommerce'), 'option_value' => 'before_add'),
- array('option_label' => __('To the right of add to cart button', 'offers-for-woocommerce'), 'option_value' => 'right_of_add'),
- array('option_label' => __('After product price', 'offers-for-woocommerce'), 'option_value' => 'after_price'),
- array('option_label' => __('After product tabs', 'offers-for-woocommerce'), 'option_value' => 'after_tabs')
- ))
- );
+ public function my_enqueue_colour_picker() {
+ wp_enqueue_script('farbtastic');
+ wp_enqueue_style('farbtastic');
+ }
/**
- * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_class'
- * Make Offer Button Class
+ * Callback - Options Page intro text
+ * @since 0.1.0
*/
- add_settings_field(
- 'display_setting_custom_make_offer_btn_class', // ID
- __('Button Class', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_text'), // Callback TEXT input
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_custom_make_offer_btn_class',
- 'input_required' => FALSE,
- 'description' => __('Set a custom CSS class name for the offer button.', 'offers-for-woocommerce'),
- )
- );
+ public function offers_for_woocommerce_options_page_intro_text() {
+ print('' . __('Complete the form below and click Save Changes button to update your settings.', 'offers-for-woocommerce') . '
');
+ }
/**
- * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_text'
- * Make Offer Button Text
+ * Callback - Options Page - Output a 'text' input field for options page form
+ * @since 0.1.0
+ * @param $args - Params to define 'option_name','input_label'
*/
- add_settings_field(
- 'display_setting_custom_make_offer_btn_text', // ID
- __('Button Text', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_text'), // Callback TEXT input
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_custom_make_offer_btn_text',
- 'input_required' => FALSE,
- 'description' => __('Set the text you would like to be displayed in the offer button.', 'offers-for-woocommerce'),
- )
- );
+ public function offers_for_woocommerce_options_page_output_input_text($args) {
+ $options = get_option($args['option_name']);
+ $description = isset($args['description']) ? $args['description'] : '';
+ $field_label = $args['input_label'];
+ $field_required = ($args['input_required']) ? ' required="required" ' : '';
+ printf(
+ ' ', isset($options[$field_label]) ? esc_attr($options[$field_label]) : ''
+ );
+
+ echo '' . $description . '
';
+ }
/**
- * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_text_color'
- * Make Offer Button Text Color
+ * Callback - Options Page - Output a 'Checkbox' input field for options page form
+ * @since 0.1.0
+ * @param $args - Params to define 'option_name','input_label'
*/
- add_settings_field(
- 'display_setting_custom_make_offer_btn_text_color', // ID
- __('Button Text Color', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_colorpicker'), // Callback TEXT input
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_custom_make_offer_btn_text_color',
- 'input_required' => FALSE,
- 'description' => __('Use the color-picker to choose the font color for the text on your offer buttons.', 'offers-for-woocommerce'),
- )
- );
+ public static function offers_for_woocommerce_options_page_output_input_checkbox($args) {
+ $options = get_option($args['option_name']);
+ $description = isset($args['description']) ? $args['description'] : '';
+ $field_label = $args['input_label'];
+ $field_required = ($args['input_required'] === true) ? ' required="required" ' : '';
+ $is_checked = (isset($options[$field_label])) ? $options[$field_label] : '0';
+ print(
+ ' ' . $description
+ );
+ }
/**
- * Add field - 'Display Settings' - 'display_setting_custom_make_offer_btn_color'
- * Make Offer Button Text Color
+ * Callback - Options Page - Output a 'Select' input field for options page form
+ * @since 0.1.0
+ * @param $args - Params to define 'option_name','input_label','input_required,'options'
*/
- add_settings_field(
- 'display_setting_custom_make_offer_btn_color', // ID
- __('Button Color', 'offers-for-woocommerce'), // Title
- array($this, 'offers_for_woocommerce_options_page_output_input_colorpicker'), // Callback TEXT input
- 'offers_for_woocommerce_display_settings', // Page
- 'display_settings', // Section
- array(
- 'option_name' => 'offers_for_woocommerce_options_display',
- 'input_label' => 'display_setting_custom_make_offer_btn_color',
- 'input_required' => FALSE,
- 'description' => __('Use the color-picker to choose the background color for your offer buttons.', 'offers-for-woocommerce'),
- )
- );
- }
-
-// END - angelleye_ofwc_intialize_options
-
- /**
- * Enqueue the colour picker
- * This is called by function 'enqueue_admin_scripts'
- * @since 0.1.0
- */
- public function my_enqueue_colour_picker() {
- wp_enqueue_script('farbtastic');
- wp_enqueue_style('farbtastic');
- }
-
- /**
- * Callback - Options Page intro text
- * @since 0.1.0
- */
- public function offers_for_woocommerce_options_page_intro_text() {
- print('' . __('Complete the form below and click Save Changes button to update your settings.', 'offers-for-woocommerce') . '
');
- }
-
- /**
- * Callback - Options Page - Output a 'text' input field for options page form
- * @since 0.1.0
- * @param $args - Params to define 'option_name','input_label'
- */
- public function offers_for_woocommerce_options_page_output_input_text($args) {
- $options = get_option($args['option_name']);
- $description = isset($args['description']) ? $args['description'] : '';
- $field_label = $args['input_label'];
- $field_required = ($args['input_required']) ? ' required="required" ' : '';
- printf(
- ' ', isset($options[$field_label]) ? esc_attr($options[$field_label]) : ''
- );
-
- echo '' . $description . '
';
- }
-
- /**
- * Callback - Options Page - Output a 'Checkbox' input field for options page form
- * @since 0.1.0
- * @param $args - Params to define 'option_name','input_label'
- */
- public static function offers_for_woocommerce_options_page_output_input_checkbox($args) {
- $options = get_option($args['option_name']);
- $description = isset($args['description']) ? $args['description'] : '';
- $field_label = $args['input_label'];
- $field_required = ($args['input_required'] === true) ? ' required="required" ' : '';
- $is_checked = (isset($options[$field_label])) ? $options[$field_label] : '0';
- print(
- ' ' . $description
- );
- }
-
- /**
- * Callback - Options Page - Output a 'Select' input field for options page form
- * @since 0.1.0
- * @param $args - Params to define 'option_name','input_label','input_required,'options'
- */
- public function offers_for_woocommerce_options_page_output_input_select($args) {
- $options = get_option($args['option_name']);
- $description = isset($args['description']) ? $args['description'] : '';
- $field_label = $args['input_label'];
- $field_required = ($args['input_required'] === true) ? ' required="required" ' : '';
- $multiple = (isset($args['multiple']) && $args['multiple'] === true) ? ' multiple="multiple" ' : '';
- $field_label_multiple = (isset($args['multiple']) && $args['multiple'] === true) ? '[]' : '';
- $extra_classes = (!empty($args['extra_classes'])) ? ' class="' . $args['extra_classes'] . '" ' : '';
+ public function offers_for_woocommerce_options_page_output_input_select($args) {
+ $options = get_option($args['option_name']);
+ $description = isset($args['description']) ? $args['description'] : '';
+ $field_label = $args['input_label'];
+ $field_required = ($args['input_required'] === true) ? ' required="required" ' : '';
+ $multiple = (isset($args['multiple']) && $args['multiple'] === true) ? ' multiple="multiple" ' : '';
+ $field_label_multiple = (isset($args['multiple']) && $args['multiple'] === true) ? '[]' : '';
+ $extra_classes = (!empty($args['extra_classes'])) ? ' class="' . $args['extra_classes'] . '" ' : '';
- print(
- ' '
- );
- foreach ($args['options'] as $option) {
- if (isset($args['multiple']) && $args['multiple'] === true) {
- $is_selected = (isset($options[$field_label]) && in_array($option['option_value'], $options[$field_label])) ? 'selected="selected"' : '';
- } else {
- $is_selected = (isset($options[$field_label]) && $options[$field_label] == $option['option_value']) ? 'selected="selected"' : '';
- }
print(
- '' . $option['option_label'] . ' '
+ ' '
);
- }
+ foreach ($args['options'] as $option) {
+ if (isset($args['multiple']) && $args['multiple'] === true) {
+ $is_selected = (isset($options[$field_label]) && in_array($option['option_value'], $options[$field_label])) ? 'selected="selected"' : '';
+ } else {
+ $is_selected = (isset($options[$field_label]) && $options[$field_label] == $option['option_value']) ? 'selected="selected"' : '';
+ }
+ print(
+ '' . $option['option_label'] . ' '
+ );
+ }
- print(
- ''
- );
+ print(
+ ''
+ );
- echo '' . $description . '
';
- }
+ echo '' . $description . '
';
+ }
- /**
- * Callback - Options Page - Output a grouping of checkboxes for options page form
- * @since 1.1.3
- * @param $args - Params to define 'option_name','option_label','option_disabled'
- */
- public function offers_for_woocommerce_options_page_output_checkbox_group($args) {
- $options = get_option($args['option_name']);
- $description = isset($args['description']) ? $args['description'] : '';
- $field_label = $args['input_label'];
-
- echo '';
- echo '';
- }
- /**
- * Callback - Options Page - Output a 'colorpicker' input field for options page form
- * @since 0.1.0
- * @param $args - Params to define 'option_name','input_label'
- */
- public function offers_for_woocommerce_options_page_output_input_colorpicker($args) {
- $options = get_option($args['option_name']);
- $description = isset($args['description']) ? $args['description'] : '';
- $field_label = $args['input_label'];
- $field_required = ($args['input_required']) ? ' required="required" ' : '';
+ /**
+ * Callback - Options Page - Output a 'colorpicker' input field for options page form
+ * @since 0.1.0
+ * @param $args - Params to define 'option_name','input_label'
+ */
+ public function offers_for_woocommerce_options_page_output_input_colorpicker($args) {
+ $options = get_option($args['option_name']);
+ $description = isset($args['description']) ? $args['description'] : '';
+ $field_label = $args['input_label'];
+ $field_required = ($args['input_required']) ? ' required="required" ' : '';
- echo '');
- echo '';
+ echo '';
- echo '' . $description . '
';
- }
+ echo '' . $description . '
';
+ }
- /**
- * Return an instance of this class
- * @since 0.1.0
- * @return object A single instance of this class
- */
- public static function get_instance() {
/**
- * If not super admin or shop manager, return
+ * Return an instance of this class
+ * @since 0.1.0
+ * @return object A single instance of this class
*/
- if (self::checkForProActive()) {
- if (!(current_user_can('vendor') || current_user_can('administrator'))) {
- return;
+ public static function get_instance() {
+ /**
+ * If not super admin or shop manager, return
+ */
+ if (self::checkForProActive()) {
+ if (!(current_user_can('vendor') || current_user_can('administrator'))) {
+ return;
+ }
+ } else {
+ if ((!is_super_admin()) && (!current_user_can('edit_woocommerce_offers'))) {
+ return;
+ }
}
- } else {
- if ((!is_super_admin()) && (!current_user_can('edit_woocommerce_offers'))) {
- return;
+ /*
+ * If the single instance hasn't been set, set it now
+ */
+ if (null == self::$instance) {
+ self::$instance = new self;
}
+ return self::$instance;
}
- /*
- * If the single instance hasn't been set, set it now
+
+ /**
+ * Register and enqueue admin-specific style sheet
+ * @since 0.1.0
+ * @return null Return early if no settings page is registered
*/
- if (null == self::$instance) {
- self::$instance = new self;
- }
- return self::$instance;
- }
+ public function enqueue_admin_styles() {
+ wp_enqueue_style('offers-for-woocommerce-admin', plugins_url('assets/css/offers-for-woocommerce-admin.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ wp_enqueue_style('datetimepicker', plugins_url('assets/css/jquery.datetimepicker.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ if (!isset($this->plugin_screen_hook_suffix)) {
+ return;
+ }
+ $screen = get_current_screen();
- /**
- * Register and enqueue admin-specific style sheet
- * @since 0.1.0
- * @return null Return early if no settings page is registered
- */
- public function enqueue_admin_styles() {
- wp_enqueue_style('offers-for-woocommerce-admin', plugins_url('assets/css/offers-for-woocommerce-admin.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
- if (!isset($this->plugin_screen_hook_suffix)) {
- return;
- }
- $screen = get_current_screen();
+ if (("edit-woocommerce_offer" == $screen->id || "woocommerce_offer" == $screen->id || $this->plugin_screen_hook_suffix == $screen->id)) {
+ // Bootstrap styles for modal
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-boostrap-custom', plugins_url('assets/css/bootstrap-custom.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
- if (("edit-woocommerce_offer" == $screen->id || "woocommerce_offer" == $screen->id || $this->plugin_screen_hook_suffix == $screen->id)) {
- // Bootstrap styles for modal
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-boostrap-custom', plugins_url('assets/css/bootstrap-custom.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ // jQuery styles
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-ui', plugins_url('assets/css/jquery-ui.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-ui-structure', plugins_url('assets/css/jquery-ui.structure.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-ui-theme', plugins_url('assets/css/jquery-ui.theme.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
- // jQuery styles
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-ui', plugins_url('assets/css/jquery-ui.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-ui-structure', plugins_url('assets/css/jquery-ui.structure.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-ui-theme', plugins_url('assets/css/jquery-ui.theme.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ // admin styles
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles', plugins_url('assets/css/admin.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
- // admin styles
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles', plugins_url('assets/css/admin.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ // chosen js styles
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-chosen', plugins_url('assets/css/chosen/chosen.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ }
- // chosen js styles
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-admin-styles-jquery-chosen', plugins_url('assets/css/chosen/chosen.min.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ if ("product" == $screen->id && is_admin()) {
+ // admin styles - edit product
+ wp_enqueue_style('offers-for-woocommerce-angelleye-offers-edit-product-styles', plugins_url('assets/css/edit-product.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ }
+ if ("settings_page_offers-for-woocommerce" == $screen->id && is_admin()) {
+ wp_enqueue_style('woocommerce_admin_styles');
+ }
}
- if ("product" == $screen->id && is_admin()) {
- // admin styles - edit product
- wp_enqueue_style('offers-for-woocommerce-angelleye-offers-edit-product-styles', plugins_url('assets/css/edit-product.css', __FILE__), array(), Angelleye_Offers_For_Woocommerce::VERSION);
+ public static function load_email_templates_script() {
+ //Send Test Emails
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-settings-test-email-scripts',
+ plugins_url('/assets/js/admin-settings-test-email-scripts.js', __FILE__),
+ array('jquery'),
+ Angelleye_Offers_For_Woocommerce::VERSION,
+ false);
+ $current_user = wp_get_current_user();
+ $local_vars = array(
+ 'email' => $current_user->user_email,
+ 'name' => $current_user->user_firstname,
+ 'surname' => $current_user->user_lastname,
+ 'phone' => get_user_meta($current_user->ID, 'billing_phone', true),
+ 'billing_company' => get_user_meta($current_user->ID, 'billing_company', true),
+ 'billing_address_1' => get_user_meta($current_user->ID, 'billing_address_1', true),
+ 'billing_address_2' => get_user_meta($current_user->ID, 'billing_address_2', true),
+ 'billing_state' => get_user_meta($current_user->ID, 'billing_state', true),
+ 'billing_postcode' => get_user_meta($current_user->ID, 'billing_postcode', true),
+ 'shipping_first_name' => $current_user->user_firstname,
+ 'shipping_last_name' => $current_user->user_lastname,
+ 'shipping_company' => get_user_meta($current_user->ID, 'shipping_company', true),
+ 'shipping_address_1' => get_user_meta($current_user->ID, 'shipping_address_1', true),
+ 'shipping_address_2' => get_user_meta($current_user->ID, 'shipping_address_2', true),
+ 'shipping_city' => get_user_meta($current_user->ID, 'shipping_city', true),
+ 'shipping_state' => get_user_meta($current_user->ID, 'shipping_state', true),
+ 'shipping_postcode' => get_user_meta($current_user->ID, 'shipping_postcode', true),
+ 'woo_currency_symbol' => get_woocommerce_currency_symbol(),
+ 'email_toggle_button_nonce' => wp_create_nonce('activate_email_templates'),
+ 'field_required' => __('Please fill in this field.', 'offers-for-woocommerce'),
+ );
+ wp_localize_script('offers-for-woocommerce-angelleye-offers-admin-settings-test-email-scripts', 'ofw_er', $local_vars);
}
- }
- /**
- * Register and enqueue admin-specific JavaScript
- * @since 0.1.0
- * @return null Return early if no settings page is registered
- */
- public function enqueue_admin_scripts() {
- $screen = get_current_screen();
- wp_enqueue_script('offers-for-woocommerce-admin', plugins_url('assets/js/offers-for-woocommerce-admin.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- if (!isset($this->plugin_screen_hook_suffix) || $screen->action == 'add') {
- return;
- }
+ /**
+ * Register and enqueue admin-specific JavaScript
+ * @since 0.1.0
+ * @return null Return early if no settings page is registered
+ */
+ public function enqueue_admin_scripts() {
+ $screen = get_current_screen();
+ wp_enqueue_script('offers-for-woocommerce-admin', plugins_url('assets/js/offers-for-woocommerce-admin.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ if (!isset($this->plugin_screen_hook_suffix) || $screen->action == 'add') {
+ return;
+ }
- if ($this->plugin_screen_hook_suffix == $screen->id && is_admin()) {
- // load color picker
- $this->my_enqueue_colour_picker();
-
- // Jquery UI js for Sortable.
- wp_enqueue_script('jquery-ui-core');
- wp_enqueue_script('jquery-ui-sortable');
- // Admin footer scripts
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-footer-scripts', plugins_url('assets/js/admin-footer-scripts.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
-
- // autoNumeric js
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-auto-numeric', plugins_url('../public/assets/js/autoNumeric.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
-
- // Admin settings scripts
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-settings-scripts', plugins_url('assets/js/admin-settings-scripts.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- wp_localize_script('offers-for-woocommerce-angelleye-offers-admin-settings-scripts', 'ofw_param', array(
- 'ofw_admin_js_currency_position' => get_option('woocommerce_currency_pos'),
- 'ofw_admin_js_thousand_separator' => wc_get_price_thousand_separator(),
- 'ofw_admin_js_decimal_separator' => wc_get_price_decimal_separator(),
- 'ofw_admin_js_number_of_decimals' => wc_get_price_decimals(),
- ));
+ if ($this->plugin_screen_hook_suffix == $screen->id && is_admin()) {
+ // load color picker
+ $this->my_enqueue_colour_picker();
+
+ // Jquery UI js for Sortable.
+ wp_enqueue_script('jquery-ui-core');
+ wp_enqueue_script('jquery-ui-sortable');
+ // Admin footer scripts
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-footer-scripts', plugins_url('assets/js/admin-footer-scripts.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+
+ // autoNumeric js
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-auto-numeric', plugins_url('../public/assets/js/autoNumeric.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+
+ // Admin settings scripts
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-settings-scripts', plugins_url('assets/js/admin-settings-scripts.js', __FILE__), array(
+ 'jquery',
+ 'jquery-ui-core',
+ 'jquery-ui-sortable',
+ 'wc-enhanced-select'), Angelleye_Offers_For_Woocommerce::VERSION);
+ wp_localize_script('offers-for-woocommerce-angelleye-offers-admin-settings-scripts', 'ofw_param', array(
+ 'ofw_admin_js_currency_position' => get_option('woocommerce_currency_pos'),
+ 'ofw_admin_js_thousand_separator' => wc_get_price_thousand_separator(),
+ 'ofw_admin_js_decimal_separator' => wc_get_price_decimal_separator(),
+ 'ofw_admin_js_number_of_decimals' => wc_get_price_decimals(),
+ ));
+
+ // Chosen js
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-chosen', plugins_url('assets/js/chosen.jquery.min.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ }
+ if ("edit-woocommerce_offer" == $screen->id && is_admin()) {
+ // Admin actions
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-actions', plugins_url('assets/js/admin-actions.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- // Chosen js
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-chosen', plugins_url('assets/js/chosen.jquery.min.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- }
- if ("edit-woocommerce_offer" == $screen->id && is_admin()) {
- // Admin actions
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-actions', plugins_url('assets/js/admin-actions.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ // Bootstrap modal.js
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-bootstrap-modal', plugins_url('assets/js/bootstrap-modal.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- // Bootstrap modal.js
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-bootstrap-modal', plugins_url('assets/js/bootstrap-modal.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ // jQuery.confirm.js
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-confirm-min', plugins_url('assets/js/jquery.confirm.min.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ }
+ if ("woocommerce_offer" == $screen->id && is_admin()) {
+ // Jquery datepicker.js
+ wp_enqueue_script('jquery-ui');
+ wp_enqueue_script('jquery-ui-datepicker');
+ wp_enqueue_script('timepicker', plugins_url('assets/js/jquery.datetimepicker.full.min.js', __FILE__), array('jquery'), '1.2');
+ // autoNumeric js
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-auto-numeric', plugins_url('../public/assets/js/autoNumeric.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+
+ // admin scripts
+ wp_enqueue_script('offers-for-woocommerce-admin-script', plugins_url('assets/js/admin.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ global $post, $wpdb;
+ $ofw_offer_expiration_date_show = 'false';
+ $expiration_date = get_post_meta($post->ID, 'offer_expiration_date', true);
+ if ((isset($expiration_date) && !empty($expiration_date)) && ( strtotime($expiration_date) < strtotime("today") )) {
+ $ofw_offer_expiration_date_show = 'true';
+ }
+ wp_localize_script('offers-for-woocommerce-admin-script', 'ofw_param', array(
+ 'ofw_offer_expiration_date_show' => $ofw_offer_expiration_date_show,
+ 'ofw_admin_js_currency_position' => get_option('woocommerce_currency_pos'),
+ 'ofw_admin_js_thousand_separator' => wc_get_price_thousand_separator(),
+ 'ofw_admin_js_decimal_separator' => wc_get_price_decimal_separator(),
+ 'ofw_admin_js_number_of_decimals' => wc_get_price_decimals(),
+ ));
+ }
- // jQuery.confirm.js
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-confirm-min', plugins_url('assets/js/jquery.confirm.min.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- }
- if ("woocommerce_offer" == $screen->id && is_admin()) {
- // Jquery datepicker.js
- wp_enqueue_script('jquery-ui-datepicker');
- // autoNumeric js
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-jquery-auto-numeric', plugins_url('../public/assets/js/autoNumeric.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
-
- // admin scripts
- wp_enqueue_script('offers-for-woocommerce-admin-script', plugins_url('assets/js/admin.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
- global $post, $wpdb;
- $ofw_offer_expiration_date_show = 'false';
- $expiration_date = get_post_meta($post->ID, 'offer_expiration_date', true);
- if ((isset($expiration_date) && !empty($expiration_date)) && ( strtotime($expiration_date) < strtotime("today") )) {
- $ofw_offer_expiration_date_show = 'true';
+ if ("product" == $screen->id && is_admin()) {
+ // admin scripts - edit product
+ wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-script-edit-product', plugins_url('assets/js/edit-product.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
}
- wp_localize_script('offers-for-woocommerce-admin-script', 'ofw_param', array(
- 'ofw_offer_expiration_date_show' => $ofw_offer_expiration_date_show,
- 'ofw_admin_js_currency_position' => get_option('woocommerce_currency_pos'),
- 'ofw_admin_js_thousand_separator' => wc_get_price_thousand_separator(),
- 'ofw_admin_js_decimal_separator' => wc_get_price_decimal_separator(),
- 'ofw_admin_js_number_of_decimals' => wc_get_price_decimals(),
- ));
- }
- if ("product" == $screen->id && is_admin()) {
- // admin scripts - edit product
- wp_enqueue_script('offers-for-woocommerce-angelleye-offers-admin-script-edit-product', plugins_url('assets/js/edit-product.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ if (isset($_GET['post_type']) && 'product' === $_GET['post_type']) {
+ wp_enqueue_script('offers-for-woocommerce-angelleye-quick-edit-script', plugins_url('assets/js/admin-product-quick-edit-script.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ }
}
- if (isset($_GET['post_type']) && 'product' === $_GET['post_type']) {
- wp_enqueue_script('offers-for-woocommerce-angelleye-quick-edit-script', plugins_url('assets/js/admin-product-quick-edit-script.js', __FILE__), array('jquery'), Angelleye_Offers_For_Woocommerce::VERSION);
+ /**
+ * Register the administration menu for this plugin into the WordPress Dashboard menu.
+ * @since 0.1.0
+ */
+ public function add_plugin_admin_menu() {
+ $this->plugin_screen_hook_suffix = add_submenu_page(
+ 'options-general.php', __('Offers for WooCommerce - Settings', 'offers-for-woocommerce'), __('Offers for WooCommerce', 'offers-for-woocommerce'), 'manage_options', 'offers-for-woocommerce', array($this, 'display_plugin_admin_page'));
}
- }
-
- /**
- * Register the administration menu for this plugin into the WordPress Dashboard menu.
- * @since 0.1.0
- */
- public function add_plugin_admin_menu() {
- $this->plugin_screen_hook_suffix = add_submenu_page(
- 'options-general.php', __('Offers for WooCommerce - Settings', 'offers-for-woocommerce'), __('Offers for WooCommerce', 'offers-for-woocommerce'), 'manage_options', 'offers-for-woocommerce', array($this, 'display_plugin_admin_page'));
- }
- /**
- * Callback - Render the settings page for this plugin.
- * @since 0.1.0
- */
- public function display_plugin_admin_page() {
-
- // WooCommerce product categories
- $taxonomy = 'product_cat';
- $orderby = 'name';
- $show_count = 0; // 1 for yes, 0 for no
- $pad_counts = 0; // 1 for yes, 0 for no
- $hierarchical = 1; // 1 for yes, 0 for no
- $title = '';
- $empty = 0;
-
- $args = array(
- 'taxonomy' => $taxonomy,
- 'orderby' => $orderby,
- 'show_count' => $show_count,
- 'pad_counts' => $pad_counts,
- 'hierarchical' => $hierarchical,
- 'title_li' => $title,
- 'hide_empty' => $empty
- );
+ /**
+ * Callback - Render the settings page for this plugin.
+ * @since 0.1.0
+ */
+ public function display_plugin_admin_page() {
+
+ // WooCommerce product categories
+ $taxonomy = 'product_cat';
+ $orderby = 'name';
+ $show_count = 0; // 1 for yes, 0 for no
+ $pad_counts = 0; // 1 for yes, 0 for no
+ $hierarchical = 1; // 1 for yes, 0 for no
+ $title = '';
+ $empty = 0;
+
+ $args = array(
+ 'taxonomy' => $taxonomy,
+ 'orderby' => $orderby,
+ 'show_count' => $show_count,
+ 'pad_counts' => $pad_counts,
+ 'hierarchical' => $hierarchical,
+ 'title_li' => $title,
+ 'hide_empty' => $empty
+ );
- $product_cats = get_categories($args);
+ $product_cats = get_categories($args);
- include_once( 'views/admin.php' );
- }
+ include_once( 'views/admin.php' );
+ }
- /**
- * Add Plugin Page Action links
- * @since 0.1.0
- */
- public function ofwc_add_plugin_action_links($links, $file) {
- $plugin_basename = plugin_basename(plugin_dir_path(realpath(dirname(__FILE__))) . 'offers-for-woocommerce.php');
-
- if ($file == $plugin_basename) {
- $new_links = array(
- sprintf('%s ', admin_url('options-general.php?page=offers-for-woocommerce'), __('Configure', 'offers-for-woocommerce')),
- sprintf('%s ', 'http://www.angelleye.com/category/docs/offers-for-woocommerce/?utm_source=offers_for_woocommerce&utm_medium=docs_link&utm_campaign=offers_for_woocommerce', __('Docs', 'offers-for-woocommerce')),
- sprintf('%s ', 'https://www.angelleye.com/support', __('Support', 'offers-for-woocommerce')),
- sprintf('%s ', 'https://www.angelleye.com/product/offers-for-woocommerce/#tab-reviews', __('Write a Review', 'offers-for-woocommerce')),
- );
+ /**
+ * Add Plugin Page Action links
+ * @since 0.1.0
+ */
+ public function ofwc_add_plugin_action_links($links, $file) {
+ $plugin_basename = plugin_basename(plugin_dir_path(realpath(dirname(__FILE__))) . 'offers-for-woocommerce.php');
+
+ if ($file == $plugin_basename) {
+ $new_links = array(
+ sprintf('%s ', admin_url('options-general.php?page=offers-for-woocommerce'), __('Configure', 'offers-for-woocommerce')),
+ sprintf('%s ', 'http://www.angelleye.com/category/docs/offers-for-woocommerce/?utm_source=offers_for_woocommerce&utm_medium=docs_link&utm_campaign=offers_for_woocommerce', __('Docs', 'offers-for-woocommerce')),
+ sprintf('%s ', 'https://www.angelleye.com/support', __('Support', 'offers-for-woocommerce')),
+ sprintf('%s ', 'https://www.angelleye.com/product/offers-for-woocommerce/#tab-reviews', __('Write a Review', 'offers-for-woocommerce')),
+ );
- $links = array_merge($links, $new_links);
+ $links = array_merge($links, $new_links);
+ }
+ return $links;
}
- return $links;
- }
- /**
- * Sanitize each setting field as needed
- *
- * @param array $input Contains all settings fields as array keys
- * @since 0.1.0
- */
- public function sanitize($input) {
- $new_input = array();
- if (isset($input['general_setting_1']))
- $new_input['general_setting_1'] = absint($input['general_setting_1']);
+ /**
+ * Sanitize each setting field as needed
+ *
+ * @param array $input Contains all settings fields as array keys
+ * @since 0.1.0
+ */
+ public function sanitize($input) {
+ $new_input = array();
+ if (isset($input['general_setting_1']))
+ $new_input['general_setting_1'] = absint($input['general_setting_1']);
- if (isset($input['title']))
- $new_input['title'] = sanitize_text_field($input['title']);
+ if (isset($input['title']))
+ $new_input['title'] = sanitize_text_field($input['title']);
- return $new_input;
- }
+ return $new_input;
+ }
- /**
- * Validate each setting field as needed
- *
- * @param array $input
- * @since 0.1.0
- */
- public function offers_for_woocommerce_options_validate_callback($input) {
- return $input;
+ /**
+ * Validate each setting field as needed
+ *
+ * @param array $input
+ * @since 0.1.0
+ */
+ public function offers_for_woocommerce_options_validate_callback($input) {
+ return $input;
- // Create our array for storing the validated options
- $output = array();
+ // Create our array for storing the validated options
+ $output = array();
- // Loop through each of the incoming options
- foreach ($input as $key => $value) {
+ // Loop through each of the incoming options
+ foreach ($input as $key => $value) {
- // Check to see if the current option has a value. If so, process it.
- if (isset($input[$key])) {
+ // Check to see if the current option has a value. If so, process it.
+ if (isset($input[$key])) {
- // Strip all HTML and PHP tags and properly handle quoted strings
- $output[$key] = strip_tags(stripslashes($input[$key]));
- } // end if
- } // end foreach
- // Return the array processing any additional functions filtered by this action
- echo apply_filters('offers_for_woocommerce_options_validate_callback', $output, $input);
- }
+ // Strip all HTML and PHP tags and properly handle quoted strings
+ $output[$key] = strip_tags(stripslashes($input[$key]));
+ } // end if
+ } // end foreach
+ // Return the array processing any additional functions filtered by this action
+ echo apply_filters('offers_for_woocommerce_options_validate_callback', $output, $input);
+ }
- /**
- * Callback - Action - Add 'pending offer(s)' count to wp dashboard 'at a glance' widget
- * @since 0.1.0
- */
- public function my_add_cpt_to_dashboard($glances) {
- $post_types = get_post_types(array('_builtin' => false), 'objects');
- foreach ($post_types as $post_type) {
- if ($post_type->name == 'woocommerce_offer') {
- $num_posts = wp_count_posts($post_type->name);
- $num = number_format_i18n($num_posts->publish);
- $text = _n('Pending Offer', 'Pending Offers', $num_posts->publish);
- if ((is_super_admin()) || (current_user_can('manage_woocommerce'))) {
- $output = '' . $num . ' ' . $text . ' ';
- echo '' . $output . '';
+ /**
+ * Callback - Action - Add 'pending offer(s)' count to wp dashboard 'at a glance' widget
+ * @since 0.1.0
+ */
+ public function my_add_cpt_to_dashboard($glances) {
+ $post_types = get_post_types(array('_builtin' => false), 'objects');
+ foreach ($post_types as $post_type) {
+ if ($post_type->name == 'woocommerce_offer') {
+ $num_posts = wp_count_posts($post_type->name);
+ $num = number_format_i18n($num_posts->publish);
+ $text = _n('Pending Offer', 'Pending Offers', $num_posts->publish);
+ if ((is_super_admin()) || (current_user_can('manage_woocommerce'))) {
+ $output = '' . $num . ' ' . $text . ' ';
+ echo ' ' . $output . '';
+ }
}
}
}
- }
- public function ofw_manage_offer_admin($offer_id = null, $emails = null, $is_approve = true) {
- global $wpdb, $woocommerce;
- if (isset($_REQUEST["targetID"]) && !empty($_REQUEST["targetID"])) {
- $post_id = absint($_REQUEST["targetID"]);
- } else {
- $post_id = $offer_id;
- }
- if (isset($post_id) && $post_id > 0) {
- $post_data = get_post($post_id);
- $table = $wpdb->prefix . "posts";
- if (empty($emails)) {
- $emails = $woocommerce->mailer()->get_emails();
- }
- if ($is_approve) {
- $post_status = 'accepted-offer';
- $post_status_text = __('Accepted', 'offers-for-woocommerce');
- $email_class = 'WC_Accepted_Offer_Email';
- $template_name = 'woocommerce-offer-accepted.php';
+ public function ofw_manage_offer_admin($offer_id = null, $emails = null, $is_approve = true) {
+ global $wpdb, $woocommerce;
+ if (isset($_REQUEST["targetID"]) && !empty($_REQUEST["targetID"])) {
+ $post_id = absint($_REQUEST["targetID"]);
} else {
- $post_status = 'declined-offer';
- $post_status_text = __('Declined', 'offers-for-woocommerce');
- $email_class = 'WC_Declined_Offer_Email';
- $template_name = 'woocommerce-offer-declined.php';
- $coupon_code = !empty($_POST["coupon_code"]) ? wc_clean($_POST["coupon_code"]) : '';
+ $post_id = $offer_id;
}
- $data_array = array(
- 'post_status' => $post_status,
- 'post_modified' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
- 'post_modified_gmt' => date("Y-m-d H:i:s", current_time('timestamp', 1))
- );
+ if (isset($post_id) && $post_id > 0) {
+ $post_data = get_post($post_id);
+ $table = $wpdb->prefix . "posts";
+ if (empty($emails)) {
+ $emails = $woocommerce->mailer()->get_emails();
+ }
+ if ($is_approve) {
+ $post_status = 'accepted-offer';
+ $post_status_text = __('Accepted', 'offers-for-woocommerce');
+ $email_class = 'WC_Accepted_Offer_Email';
+ $template_name = 'woocommerce-offer-accepted.php';
+ } else {
+ $post_status = 'declined-offer';
+ $post_status_text = __('Declined', 'offers-for-woocommerce');
+ $email_class = 'WC_Declined_Offer_Email';
+ $template_name = 'woocommerce-offer-declined.php';
+ $coupon_code = !empty($_POST["coupon_code"]) ? wc_clean($_POST["coupon_code"]) : '';
+ }
+ $data_array = array(
+ 'post_status' => $post_status,
+ 'post_modified' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
+ 'post_modified_gmt' => date("Y-m-d H:i:s", current_time('timestamp', 1))
+ );
- $where = array('ID' => $post_id);
- $wpdb->update($table, $data_array, $where);
- $offer_notes = !empty($_POST['angelleye_woocommerce_offer_status_notes']) ? wc_clean(wp_slash($_POST['angelleye_woocommerce_offer_status_notes'])) : '';
- $recipient = get_post_meta($post_id, 'offer_email', true);
+ $where = array('ID' => $post_id);
+ $wpdb->update($table, $data_array, $where);
+ $offer_notes = !empty($_POST['angelleye_woocommerce_offer_status_notes']) ? wc_clean(wp_slash($_POST['angelleye_woocommerce_offer_status_notes'])) : '';
+ $recipient = get_post_meta($post_id, 'offer_email', true);
- $offer_id = $post_id;
- $offer_uid = get_post_meta($post_id, 'offer_uid', true);
- $offer_name = get_post_meta($post_id, 'offer_name', true);
- $offer_email = $recipient;
- $product_id = get_post_meta($post_id, 'offer_product_id', true);
- $variant_id = get_post_meta($post_id, 'offer_variation_id', true);
- $product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
- $is_offer_buyer_countered_status = ( $post_data->post_status == 'buyercountered-offer' ) ? true : false;
- $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
- $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
- $product_shipping_cost = get_post_meta($post_id, 'offer_shipping_cost', true);
- $product_total = number_format(($product_qty * $product_price_per), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator());
- if ($is_offer_buyer_countered_status) {
- update_post_meta($post_id, 'offer_quantity', $product_qty);
- update_post_meta($post_id, 'offer_price_per', $product_price_per);
- update_post_meta($post_id, 'offer_shipping_cost', $product_shipping_cost);
- update_post_meta($post_id, 'offer_amount', $product_total);
- }
- $offer_args = array(
- 'recipient' => $recipient,
- 'offer_email' => $offer_email,
- 'offer_name' => $offer_name,
- 'offer_id' => $offer_id,
- 'offer_uid' => $offer_uid,
- 'product_id' => $product_id,
- 'product_url' => $product->get_permalink(),
- 'variant_id' => $variant_id,
- 'product' => $product,
- 'product_qty' => $product_qty,
- 'product_price_per' => $product_price_per,
- 'product_shipping_cost' => $product_shipping_cost,
- 'product_total' => $product_total,
- 'offer_notes' => $offer_notes,
- 'coupon_code' => isset($coupon_code) ? $coupon_code : ''
- );
- if ($variant_id) {
- if ($product->get_sku()) {
- $identifier = $product->get_sku();
+ $offer_id = $post_id;
+ $offer_uid = get_post_meta($post_id, 'offer_uid', true);
+ $offer_name = get_post_meta($post_id, 'offer_name', true);
+ $offer_email = $recipient;
+ $product_id = get_post_meta($post_id, 'offer_product_id', true);
+ $variant_id = get_post_meta($post_id, 'offer_variation_id', true);
+ $product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
+ $is_offer_buyer_countered_status = ( $post_data->post_status == 'buyercountered-offer' ) ? true : false;
+ $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
+ $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
+ $product_shipping_cost = get_post_meta($post_id, 'offer_shipping_cost', true);
+ //$product_total = number_format(($product_qty * $product_price_per), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator());
+ $product_total = ($product_qty * $product_price_per);
+ if ($is_offer_buyer_countered_status) {
+ update_post_meta($post_id, 'offer_quantity', $product_qty);
+ update_post_meta($post_id, 'offer_price_per', $product_price_per);
+ update_post_meta($post_id, 'offer_shipping_cost', $product_shipping_cost);
+ update_post_meta($post_id, 'offer_amount', $product_total);
+ }
+ $offer_args = array(
+ 'recipient' => $recipient,
+ 'offer_email' => $offer_email,
+ 'offer_name' => $offer_name,
+ 'offer_id' => $offer_id,
+ 'offer_uid' => $offer_uid,
+ 'product_id' => $product_id,
+ 'product_url' => $product->get_permalink(),
+ 'variant_id' => $variant_id,
+ 'product' => $product,
+ 'product_qty' => $product_qty,
+ 'product_price_per' => $product_price_per,
+ 'product_shipping_cost' => $product_shipping_cost,
+ 'product_total' => $product_total,
+ 'offer_notes' => $offer_notes,
+ 'coupon_code' => isset($coupon_code) ? $coupon_code : ''
+ );
+ if ($variant_id) {
+ if ($product->get_sku()) {
+ $identifier = $product->get_sku();
+ } else {
+ $identifier = '#' . $product->get_id();
+ }
+ $attributes = $product->get_variation_attributes();
+ $extra_data = ' – ' . implode(', ', $attributes);
+ $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'offers-for-woocommerce'), $identifier, $product->get_title(), $extra_data);
} else {
- $identifier = '#' . $product->get_id();
+ $offer_args['product_title_formatted'] = $product->get_formatted_name();
+ }
+ if (isset($email_class) && !empty($email_class)) {
+ $new_email = $emails[$email_class];
+ $new_email->recipient = $recipient;
+ $new_email->plugin_slug = 'offers-for-woocommerce';
+ $new_email->template_html_path = untrailingslashit(OFW_PLUGIN_URL) . '/admin/includes/emails/';
+ $new_email->template_plain_path = untrailingslashit(OFW_PLUGIN_URL) . '/admin/includes/emails/plain/';
+ $new_email->template_html = $template_name;
+ $new_email->template_plain = $template_name;
+ $new_email->trigger($offer_args);
+ }
+ $comment_text = "" . __('Updated - Status:', 'offers-for-woocommerce') . " ";
+ $comment_text .= $post_status_text;
+ if (isset($offer_notes) && $offer_notes != '') {
+ $comment_text .= '' . nl2br($offer_notes);
+ }
+ $data = array(
+ 'comment_post_ID' => '',
+ 'comment_author' => 'admin',
+ 'comment_author_email' => '',
+ 'comment_author_url' => '',
+ 'comment_content' => $comment_text,
+ 'comment_type' => '',
+ 'comment_parent' => 0,
+ 'user_id' => get_current_user_id(),
+ 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
+ 'comment_agent' => '',
+ 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
+ 'comment_approved' => 'post-trashed',
+ );
+ $new_comment_id = wp_insert_comment($data);
+ if ($new_comment_id) {
+ add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true);
}
- $attributes = $product->get_variation_attributes();
- $extra_data = ' – ' . implode(', ', $attributes);
- $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'offers-for-woocommerce'), $identifier, $product->get_title(), $extra_data);
- } else {
- $offer_args['product_title_formatted'] = $product->get_formatted_name();
- }
- if (isset($email_class) && !empty($email_class)) {
- $new_email = $emails[$email_class];
- $new_email->recipient = $recipient;
- $new_email->plugin_slug = 'offers-for-woocommerce';
- $new_email->template_html_path = untrailingslashit(OFW_PLUGIN_URL) . '/admin/includes/emails/';
- $new_email->template_plain_path = untrailingslashit(OFW_PLUGIN_URL) . '/admin/includes/emails/plain/';
- $new_email->template_html = $template_name;
- $new_email->template_plain = $template_name;
- $new_email->trigger($offer_args);
- }
- $comment_text = "" . __('Updated - Status:', 'offers-for-woocommerce') . " ";
- $comment_text .= $post_status_text;
- if (isset($offer_notes) && $offer_notes != '') {
- $comment_text .= '' . nl2br($offer_notes);
- }
- $data = array(
- 'comment_post_ID' => '',
- 'comment_author' => 'admin',
- 'comment_author_email' => '',
- 'comment_author_url' => '',
- 'comment_content' => $comment_text,
- 'comment_type' => '',
- 'comment_parent' => 0,
- 'user_id' => get_current_user_id(),
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
- 'comment_agent' => '',
- 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
- 'comment_approved' => 'post-trashed',
- );
- $new_comment_id = wp_insert_comment($data);
- if ($new_comment_id) {
- add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true);
- }
- do_action('angelleye_ofw_capture_authorization_payment', $post_id, $post_status, true );
+ do_action('angelleye_ofw_capture_authorization_payment', $post_id, $post_status, true);
+ }
}
- }
- /*
- * Action - Ajax 'approve offer' from manage list
- * @since 0.1.0
- */
+ /*
+ * Action - Ajax 'approve offer' from manage list
+ * @since 0.1.0
+ */
- public function approveOfferFromGridCallback() {
- if (is_admin() && ( is_ajax() || (isset($_GET['ofw_from_email']) && $_GET['ofw_from_email'] == true))) {
- global $post, $wpdb; // this is how you get access to the database
- $post_id = '';
- if (isset($_GET['targetID']) && !empty($_GET['targetID'])) {
- $post_id = absint($_GET["targetID"]);
- }
- do_action('ofw_before_auto_approve_offer_admin', $post_id);
- $this->ofw_manage_offer_admin($post_id, '', true);
- do_action('ofw_after_auto_approve_offer_admin', $post_id);
- if (is_ajax()) {
- die(); // this is required to return a proper result
+ public function approveOfferFromGridCallback() {
+ if (is_admin() && ( is_ajax() || (isset($_GET['ofw_from_email']) && $_GET['ofw_from_email'] == true))) {
+ global $post, $wpdb; // this is how you get access to the database
+ $post_id = '';
+ if (isset($_GET['targetID']) && !empty($_GET['targetID'])) {
+ $post_id = absint($_GET["targetID"]);
+ }
+ do_action('ofw_before_auto_approve_offer_admin', $post_id);
+ $this->ofw_manage_offer_admin($post_id, '', true);
+ do_action('ofw_after_auto_approve_offer_admin', $post_id);
+ if (is_ajax()) {
+ die(); // this is required to return a proper result
+ }
}
}
- }
- /*
- * Action - Ajax 'decline offer' from manage list
- * @since 0.1.0
- */
+ /*
+ * Action - Ajax 'decline offer' from manage list
+ * @since 0.1.0
+ */
- public function declineOfferFromGridCallback() {
- if (is_admin() && ( is_ajax() || (isset($_GET['ofw_from_email']) && $_GET['ofw_from_email'] == true))) {
- global $wpdb; // this is how you get access to the database
- $post_id = '';
- if (isset($_REQUEST['targetID']) && !empty($_REQUEST['targetID'])) {
- $post_id = absint($_REQUEST["targetID"]);
- }
- do_action('ofw_before_auto_decline_offer_admin', $post_id);
- $this->ofw_manage_offer_admin($post_id, '', false);
- do_action('ofw_after_auto_decline_offer_admin', $post_id);
- if (is_ajax()) {
- die(); // this is required to return a proper result
+ public function declineOfferFromGridCallback() {
+ if (is_admin() && ( is_ajax() || (isset($_GET['ofw_from_email']) && $_GET['ofw_from_email'] == true))) {
+ global $wpdb; // this is how you get access to the database
+ $post_id = '';
+ if (isset($_REQUEST['targetID']) && !empty($_REQUEST['targetID'])) {
+ $post_id = absint($_REQUEST["targetID"]);
+ }
+ do_action('ofw_before_auto_decline_offer_admin', $post_id);
+ $this->ofw_manage_offer_admin($post_id, '', false);
+ do_action('ofw_after_auto_decline_offer_admin', $post_id);
+ if (is_ajax()) {
+ die(); // this is required to return a proper result
+ }
}
}
- }
-
- /*
- * Action - Ajax 'add offer note' from manage offer details
- * @since 0.1.0
- */
- public function addOfferNoteCallback() {
- if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
- $post_id = absint($_POST["targetID"]);
- // Get current data for Offer
- $post_data = get_post($post_id);
- // Filter Post Status Label
- $post_status_text = (strtolower($post_data->post_status) == 'publish') ? 'Pending' : $post_data->post_status;
- $post_status_text = ucwords(str_replace("-", " ", str_replace("offer", " ", strtolower($post_status_text))));
+ /*
+ * Action - Ajax 'add offer note' from manage offer details
+ * @since 0.1.0
+ */
- $noteSendToBuyer = !empty($_POST["noteSendToBuyer"]) ? '1' : '';
- $offer_notes = wc_clean(wp_slash($_POST['noteContent']));
+ public function addOfferNoteCallback() {
+ if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
+ $post_id = absint($_POST["targetID"]);
+ // Get current data for Offer
+ $post_data = get_post($post_id);
+ // Filter Post Status Label
+ $post_status_text = (strtolower($post_data->post_status) == 'publish') ? 'Pending' : $post_data->post_status;
+ $post_status_text = ucwords(str_replace("-", " ", str_replace("offer", " ", strtolower($post_status_text))));
- $current_user = wp_get_current_user();
+ $noteSendToBuyer = !empty($_POST["noteSendToBuyer"]) ? '1' : '';
+ $offer_notes = wc_clean(wp_slash($_POST['noteContent']));
- // Insert WP comment
- $comment_text = "" . __('Offer Note:', 'offers-for-woocommerce') . " ";
- if ($noteSendToBuyer != '1') {
- $comment_text .= " " . __('(admin only)', 'offers-for-woocommerce');
- } else {
- $comment_text .= " " . __('(sent to buyer)', 'offers-for-woocommerce');
- }
- $comment_text .= " " . $offer_notes;
+ $current_user = wp_get_current_user();
- $data = array(
- 'comment_post_ID' => '',
- 'comment_author' => $current_user->user_login,
- 'comment_author_email' => $current_user->user_email,
- 'comment_author_url' => '',
- 'comment_content' => $comment_text,
- 'comment_type' => '',
- 'comment_parent' => 0,
- 'user_id' => get_current_user_id(),
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
- 'comment_agent' => '',
- 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
- 'comment_approved' => 'post-trashed',
- );
- $new_comment_id = wp_insert_comment($data);
-
- // insert comment meta
- if ($new_comment_id) {
- add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true);
- }
+ // Insert WP comment
+ $comment_text = "" . __('Offer Note:', 'offers-for-woocommerce') . " ";
+ if ($noteSendToBuyer != '1') {
+ $comment_text .= " " . __('(admin only)', 'offers-for-woocommerce');
+ } else {
+ $comment_text .= " " . __('(sent to buyer)', 'offers-for-woocommerce');
+ }
+ $comment_text .= " " . $offer_notes;
+
+ $data = array(
+ 'comment_post_ID' => '',
+ 'comment_author' => $current_user->user_login,
+ 'comment_author_email' => $current_user->user_email,
+ 'comment_author_url' => '',
+ 'comment_content' => $comment_text,
+ 'comment_type' => '',
+ 'comment_parent' => 0,
+ 'user_id' => get_current_user_id(),
+ 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
+ 'comment_agent' => '',
+ 'comment_date' => date("Y-m-d H:i:s", current_time('timestamp', 0)),
+ 'comment_approved' => 'post-trashed',
+ );
+ $new_comment_id = wp_insert_comment($data);
- if ($new_comment_id) {
+ // insert comment meta
+ if ($new_comment_id) {
+ add_comment_meta($new_comment_id, 'angelleye_woocommerce_offer_id', $post_id, true);
+ }
- if ($noteSendToBuyer == '1') {
- // Email buyer the offer note (not private admin note)
- /**
- * Offer note email template
- * @since 0.1.0
- */
- // set recipient email
- $recipient = get_post_meta($post_id, 'offer_email', true);
- $offer_id = $post_id;
- $offer_uid = get_post_meta($post_id, 'offer_uid', true);
- $offer_name = get_post_meta($post_id, 'offer_name', true);
- $offer_email = $recipient;
-
- $product_id = get_post_meta($post_id, 'offer_product_id', true);
- $variant_id = get_post_meta($post_id, 'offer_variation_id', true);
-
- $product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
-
- // if buyercountered-offer previous then use buyer counter values
- $is_offer_buyer_countered_status = ( $post_data->post_status == 'buyercountered-offer' ) ? true : false;
-
- $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
- $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
- $product_shipping_cost = get_post_meta($post_id, 'offer_shipping_cost', true);
- $product_total = ($product_qty * $product_price_per);
-
- $offer_args = array(
- 'recipient' => $recipient,
- 'offer_email' => $offer_email,
- 'offer_name' => $offer_name,
- 'offer_id' => $offer_id,
- 'offer_uid' => $offer_uid,
- 'product_id' => $product_id,
- 'product_url' => $product->get_permalink(),
- 'variant_id' => $variant_id,
- 'product' => $product,
- 'product_qty' => $product_qty,
- 'product_price_per' => $product_price_per,
- 'product_shipping_cost' => $product_shipping_cost,
- 'product_total' => $product_total,
- 'offer_notes' => $offer_notes
- );
+ if ($new_comment_id) {
+
+ if ($noteSendToBuyer == '1') {
+ // Email buyer the offer note (not private admin note)
+ /**
+ * Offer note email template
+ * @since 0.1.0
+ */
+ // set recipient email
+ $recipient = get_post_meta($post_id, 'offer_email', true);
+ $offer_id = $post_id;
+ $offer_uid = get_post_meta($post_id, 'offer_uid', true);
+ $offer_name = get_post_meta($post_id, 'offer_name', true);
+ $offer_email = $recipient;
+
+ $product_id = get_post_meta($post_id, 'offer_product_id', true);
+ $variant_id = get_post_meta($post_id, 'offer_variation_id', true);
+
+ $product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
+
+ // if buyercountered-offer previous then use buyer counter values
+ $is_offer_buyer_countered_status = ( $post_data->post_status == 'buyercountered-offer' ) ? true : false;
+
+ $product_qty = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_quantity', true) : get_post_meta($post_id, 'offer_quantity', true);
+ $product_price_per = ( $is_offer_buyer_countered_status ) ? get_post_meta($post_id, 'offer_buyer_counter_price_per', true) : get_post_meta($post_id, 'offer_price_per', true);
+ $product_shipping_cost = get_post_meta($post_id, 'offer_shipping_cost', true);
+ $product_total = ($product_qty * $product_price_per);
+
+ $offer_args = array(
+ 'recipient' => $recipient,
+ 'offer_email' => $offer_email,
+ 'offer_name' => $offer_name,
+ 'offer_id' => $offer_id,
+ 'offer_uid' => $offer_uid,
+ 'product_id' => $product_id,
+ 'product_url' => $product->get_permalink(),
+ 'variant_id' => $variant_id,
+ 'product' => $product,
+ 'product_qty' => $product_qty,
+ 'product_price_per' => $product_price_per,
+ 'product_shipping_cost' => $product_shipping_cost,
+ 'product_total' => $product_total,
+ 'offer_notes' => $offer_notes
+ );
+
+ if ($variant_id) {
+ if ($product->get_sku()) {
+ $identifier = $product->get_sku();
+ } else {
+ $identifier = '#' . $product->get_id();
+ }
- if ($variant_id) {
- if ($product->get_sku()) {
- $identifier = $product->get_sku();
+ $attributes = $product->get_variation_attributes();
+ $extra_data = ' – ' . implode(', ', $attributes);
+ $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'offers-for-woocommerce'), $identifier, $product->get_title(), $extra_data);
} else {
- $identifier = '#' . $product->get_id();
+ $offer_args['product_title_formatted'] = $product->get_formatted_name();
}
- $attributes = $product->get_variation_attributes();
- $extra_data = ' – ' . implode(', ', $attributes);
- $offer_args['product_title_formatted'] = sprintf(__('%s – %s%s', 'offers-for-woocommerce'), $identifier, $product->get_title(), $extra_data);
- } else {
- $offer_args['product_title_formatted'] = $product->get_formatted_name();
- }
+ // the email we want to send
+ $email_class = 'WC_Offer_Note_Email';
- // the email we want to send
- $email_class = 'WC_Offer_Note_Email';
+ // load the WooCommerce Emails
+ global $woocommerce;
+ $emails = $woocommerce->mailer()->get_emails();
- // load the WooCommerce Emails
- global $woocommerce;
- $emails = $woocommerce->mailer()->get_emails();
+ // select the email we want & trigger it to send
+ $new_email = $emails[$email_class];
+ $new_email->recipient = $recipient;
- // select the email we want & trigger it to send
- $new_email = $emails[$email_class];
- $new_email->recipient = $recipient;
+ // set plugin slug in email class
+ $new_email->plugin_slug = 'offers-for-woocommerce';
- // set plugin slug in email class
- $new_email->plugin_slug = 'offers-for-woocommerce';
+ // define email template/path (html)
+ $new_email->template_html = 'woocommerce-offer-note.php';
+ $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/';
- // define email template/path (html)
- $new_email->template_html = 'woocommerce-offer-note.php';
- $new_email->template_html_path = plugin_dir_path(__FILE__) . 'includes/emails/';
+ // define email template/path (plain)
+ $new_email->template_plain = 'woocommerce-offer-note.php';
+ $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/';
- // define email template/path (plain)
- $new_email->template_plain = 'woocommerce-offer-note.php';
- $new_email->template_plain_path = plugin_dir_path(__FILE__) . 'includes/emails/plain/';
+ $new_email->trigger($offer_args);
+ }
- $new_email->trigger($offer_args);
+ $redirect_url = admin_url('post.php?post=' . $post_id . '&action=edit&noheader=true&message=11');
+ echo $redirect_url;
+ } else {
+ echo 'failed';
}
-
- $redirect_url = admin_url('post.php?post=' . $post_id . '&action=edit&noheader=true&message=11');
- echo $redirect_url;
- } else {
- echo 'failed';
+ die(); // this is required to return a proper result
}
- die(); // this is required to return a proper result
}
- }
-
- public function adminToolSetMinimumOfferPriceCallback() {
- if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
- global $wpdb;
- $processed_product_id = array();
- $errors = FALSE;
- $products = FALSE;
- $product_ids = FALSE;
- $update_count = 0;
- $where_args = array(
- 'post_type' => array('product', 'product_variation'),
- 'posts_per_page' => -1,
- 'post_status' => 'publish',
- 'suppress_filters' => 1,
- 'fields' => 'id=>parent',
- );
- $where_args['meta_query'] = array();
-
- $ofwc_bulk_action_minimum_price = ( isset($_POST["minimumPrice"]) ) ? wc_clean($_POST['minimumPrice']) : FALSE;
- $ofwc_bulk_action_price_type = ( isset($_POST["priceType"]) ) ? wc_clean($_POST['priceType']) : FALSE;
- $ofwc_bulk_action_type = ( isset($_POST["actionType"]) ) ? wc_clean($_POST['actionType']) : FALSE;
- $ofwc_bulk_action_target_type = ( isset($_POST["actionTargetType"]) ) ? wc_clean($_POST['actionTargetType']) : FALSE;
- $ofwc_bulk_action_target_where_type = ( isset($_POST["actionTargetWhereType"]) ) ? wc_clean($_POST['actionTargetWhereType']) : FALSE;
- $ofwc_bulk_action_target_where_category = ( isset($_POST["actionTargetWhereCategory"]) ) ? wc_clean($_POST['actionTargetWhereCategory']) : FALSE;
- $ofwc_bulk_action_target_where_product_type = ( isset($_POST["actionTargetWhereProductType"]) ) ? wc_clean($_POST['actionTargetWhereProductType']) : FALSE;
- $ofwc_bulk_action_target_where_price_value = ( isset($_POST["actionTargetWherePriceValue"]) ) ? wc_clean($_POST['actionTargetWherePriceValue']) : FALSE;
- $ofwc_bulk_action_target_where_stock_value = ( isset($_POST["actionTargetWhereStockValue"]) ) ? wc_clean($_POST['actionTargetWhereStockValue']) : FALSE;
- $ofw_meta_key_value = ( isset($_POST['ofw_meta_key_value']) && !empty($_POST["ofw_meta_key_value"]) ) ? wc_clean($_POST['ofw_meta_key_value']) : FALSE;
-
-
-
- if (!$ofwc_bulk_action_type && !$ofwc_bulk_action_target_type) {
- $errors = TRUE;
- }
- if (!$ofw_meta_key_value) {
- $errors = TRUE;
- }
- if ($ofwc_bulk_action_type == 'ofwc_minimum_offer_price_enable') {
- $ofwcmof = 'yes';
- } else {
- $ofwcmof = 'no';
- $ofwc_bulk_action_minimum_price = '';
- $ofwc_bulk_action_price_type = '';
- }
- // All Products
- if ($ofwc_bulk_action_target_type == 'all') {
- $products = new WP_Query($where_args);
- }
- // Featured products
- elseif ($ofwc_bulk_action_target_type == 'featured') {
- array_push($where_args['meta_query'], array(
- 'key' => '_featured',
- 'value' => 'yes'
- )
+ public function adminToolSetMinimumOfferPriceCallback() {
+ if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
+ global $wpdb;
+ $processed_product_id = array();
+ $errors = FALSE;
+ $products = FALSE;
+ $product_ids = FALSE;
+ $update_count = 0;
+ $where_args = array(
+ 'post_type' => array('product', 'product_variation'),
+ 'posts_per_page' => -1,
+ 'post_status' => 'publish',
+ 'suppress_filters' => 1,
+ 'fields' => 'id=>parent',
);
- $products = new WP_Query($where_args);
- }
- // Where
- elseif ($ofwc_bulk_action_target_type == 'where' && $ofwc_bulk_action_target_where_type) {
- // Where - By Category
- if ($ofwc_bulk_action_target_where_type == 'category' && $ofwc_bulk_action_target_where_category) {
- $where_args['product_cat'] = $ofwc_bulk_action_target_where_category;
- $products = new WP_Query($where_args);
- } // Where - By Product type
- elseif ($ofwc_bulk_action_target_where_type == 'product_type' && $ofwc_bulk_action_target_where_product_type) {
- $where_args['product_type'] = $ofwc_bulk_action_target_where_product_type;
- $products = new WP_Query($where_args);
- } // Where - By Price - greater than
- elseif ($ofwc_bulk_action_target_where_type == 'price_greater') {
- array_push($where_args['meta_query'], array(
- 'key' => '_price',
- 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '>',
- 'type' => 'DECIMAL(10,2)'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - By Price - less than
- elseif ($ofwc_bulk_action_target_where_type == 'price_less') {
- array_push($where_args['meta_query'], array(
- 'key' => '_price',
- 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '<',
- 'type' => 'DECIMAL(10,2)'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - By Stock - greater than
- elseif ($ofwc_bulk_action_target_where_type == 'stock_greater') {
- array_push($where_args['meta_query'], array(
- 'key' => '_manage_stock',
- 'value' => 'yes'
- )
- );
- array_push($where_args['meta_query'], array(
- 'key' => '_stock',
- 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '>',
- 'type' => 'NUMERIC'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - By Stock - less than
- elseif ($ofwc_bulk_action_target_where_type == 'stock_less') {
- array_push($where_args['meta_query'], array(
- 'key' => '_manage_stock',
- 'value' => 'yes'
- )
- );
- array_push($where_args['meta_query'], array(
- 'key' => '_stock',
- 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '<',
- 'type' => 'NUMERIC'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - Stock status 'instock'
- elseif ($ofwc_bulk_action_target_where_type == 'instock') {
- array_push($where_args['meta_query'], array(
- 'key' => '_stock_status',
- 'value' => 'instock'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - Stock status 'outofstock'
- elseif ($ofwc_bulk_action_target_where_type == 'outofstock') {
- array_push($where_args['meta_query'], array(
- 'key' => '_stock_status',
- 'value' => 'outofstock'
- )
- );
+ $where_args['meta_query'] = array();
+
+ $ofwc_bulk_action_minimum_price = ( isset($_POST["minimumPrice"]) ) ? wc_clean($_POST['minimumPrice']) : FALSE;
+ $ofwc_bulk_action_price_type = ( isset($_POST["priceType"]) ) ? wc_clean($_POST['priceType']) : FALSE;
+ $ofwc_bulk_action_type = ( isset($_POST["actionType"]) ) ? wc_clean($_POST['actionType']) : FALSE;
+ $ofwc_bulk_action_target_type = ( isset($_POST["actionTargetType"]) ) ? wc_clean($_POST['actionTargetType']) : FALSE;
+ $ofwc_bulk_action_target_where_type = ( isset($_POST["actionTargetWhereType"]) ) ? wc_clean($_POST['actionTargetWhereType']) : FALSE;
+ $ofwc_bulk_action_target_where_category = ( isset($_POST["actionTargetWhereCategory"]) ) ? wc_clean($_POST['actionTargetWhereCategory']) : FALSE;
+ $ofwc_bulk_action_target_where_product_type = ( isset($_POST["actionTargetWhereProductType"]) ) ? wc_clean($_POST['actionTargetWhereProductType']) : FALSE;
+ $ofwc_bulk_action_target_where_price_value = ( isset($_POST["actionTargetWherePriceValue"]) ) ? wc_clean($_POST['actionTargetWherePriceValue']) : FALSE;
+ $ofwc_bulk_action_target_where_stock_value = ( isset($_POST["actionTargetWhereStockValue"]) ) ? wc_clean($_POST['actionTargetWhereStockValue']) : FALSE;
+ $ofw_meta_key_value = ( isset($_POST['ofw_meta_key_value']) && !empty($_POST["ofw_meta_key_value"]) ) ? wc_clean($_POST['ofw_meta_key_value']) : FALSE;
+
+ if (!$ofwc_bulk_action_type && !$ofwc_bulk_action_target_type) {
+ $errors = TRUE;
+ }
+ if (!$ofw_meta_key_value) {
+ $errors = TRUE;
+ }
+ if ($ofwc_bulk_action_type == 'ofwc_minimum_offer_price_enable') {
+ $ofwcmof = 'yes';
+ } else {
+ $ofwcmof = 'no';
+ $ofwc_bulk_action_minimum_price = '';
+ $ofwc_bulk_action_price_type = '';
+ }
+
+ // All Products
+ if ($ofwc_bulk_action_target_type == 'all') {
$products = new WP_Query($where_args);
- } // Where - Sold Individually
- elseif ($ofwc_bulk_action_target_where_type == 'sold_individually') {
+ }
+ // Featured products
+ elseif ($ofwc_bulk_action_target_type == 'featured') {
array_push($where_args['meta_query'], array(
- 'key' => '_sold_individually',
+ 'key' => '_featured',
'value' => 'yes'
)
);
$products = new WP_Query($where_args);
}
- } else {
- $errors = TRUE;
- }
- }
-
- /* Update posts */
- if (!$errors && $products) {
- if (count($products->posts) < 1) {
- $errors = TRUE;
- $update_count = 'zero';
- $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
- echo $redirect_url;
- } else {
- foreach ($products->posts as $target) {
- $target_product_id = ( $target->post_parent != '0' ) ? $target->post_parent : $target->ID;
- if (get_post_type($target_product_id) == 'product' && !in_array($target_product_id, $processed_product_id)) {
- update_post_meta($target_product_id, $ofw_meta_key_value, $ofwc_bulk_action_minimum_price);
- update_post_meta($target_product_id, 'ofwc_minimum_offer_price_type', $ofwc_bulk_action_price_type);
- update_post_meta($target_product_id, 'ofwc_minimum_offer_price_enabled', $ofwcmof);
- $processed_product_id[$target_product_id] = $target_product_id;
+ // Where
+ elseif ($ofwc_bulk_action_target_type == 'where' && $ofwc_bulk_action_target_where_type) {
+ // Where - By Category
+ if ($ofwc_bulk_action_target_where_type == 'category' && $ofwc_bulk_action_target_where_category) {
+ $where_args['product_cat'] = $ofwc_bulk_action_target_where_category;
+ $products = new WP_Query($where_args);
+ } // Where - By Product type
+ elseif ($ofwc_bulk_action_target_where_type == 'product_type' && $ofwc_bulk_action_target_where_product_type) {
+ $where_args['product_type'] = $ofwc_bulk_action_target_where_product_type;
+ $products = new WP_Query($where_args);
+ } // Where - By Price - greater than
+ elseif ($ofwc_bulk_action_target_where_type == 'price_greater') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_price',
+ 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '>',
+ 'type' => 'DECIMAL(10,2)'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - By Price - less than
+ elseif ($ofwc_bulk_action_target_where_type == 'price_less') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_price',
+ 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '<',
+ 'type' => 'DECIMAL(10,2)'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - By Stock - greater than
+ elseif ($ofwc_bulk_action_target_where_type == 'stock_greater') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_manage_stock',
+ 'value' => 'yes'
+ )
+ );
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock',
+ 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '>',
+ 'type' => 'NUMERIC'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - By Stock - less than
+ elseif ($ofwc_bulk_action_target_where_type == 'stock_less') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_manage_stock',
+ 'value' => 'yes'
+ )
+ );
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock',
+ 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '<',
+ 'type' => 'NUMERIC'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - Stock status 'instock'
+ elseif ($ofwc_bulk_action_target_where_type == 'instock') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock_status',
+ 'value' => 'instock'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - Stock status 'outofstock'
+ elseif ($ofwc_bulk_action_target_where_type == 'outofstock') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock_status',
+ 'value' => 'outofstock'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - Sold Individually
+ elseif ($ofwc_bulk_action_target_where_type == 'sold_individually') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_sold_individually',
+ 'value' => 'yes'
+ )
+ );
+ $products = new WP_Query($where_args);
}
+ } else {
+ $errors = TRUE;
}
- $update_count = count($processed_product_id);
}
- if (!$errors) {
- if ($update_count == 0) {
+
+ /* Update posts */
+ if (!$errors && $products) {
+ if (count($products->posts) < 1) {
+ $errors = TRUE;
$update_count = 'zero';
+ $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
+ echo $redirect_url;
+ } else {
+ foreach ($products->posts as $target) {
+ $target_product_id = ( $target->post_parent != '0' ) ? $target->post_parent : $target->ID;
+ if (get_post_type($target_product_id) == 'product' && !in_array($target_product_id, $processed_product_id)) {
+ update_post_meta($target_product_id, $ofw_meta_key_value, $ofwc_bulk_action_minimum_price);
+ update_post_meta($target_product_id, 'ofwc_minimum_offer_price_type', $ofwc_bulk_action_price_type);
+ update_post_meta($target_product_id, 'ofwc_minimum_offer_price_enabled', $ofwcmof);
+ $processed_product_id[$target_product_id] = $target_product_id;
+ }
+ }
+ $update_count = count($processed_product_id);
}
+ if (!$errors) {
+ if ($update_count == 0) {
+ $update_count = 'zero';
+ }
- $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
- echo $redirect_url;
- } else {
- //echo 'failed';
+ $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
+ echo $redirect_url;
+ } else {
+ //echo 'failed';
+ }
+ die(); // this is required to return a proper result
}
- die(); // this is required to return a proper result
}
- }
- /*
- * Action - Ajax 'bulk enable/disable tool' from offers settings/tools
- * @since 0.1.0
- */
+ /*
+ * Action - Ajax 'bulk enable/disable tool' from offers settings/tools
+ * @since 0.1.0
+ */
- public function adminToolBulkEnableDisableCallback() {
- if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
- global $wpdb;
- $processed_product_id = array();
- $errors = FALSE;
- $products = FALSE;
- $product_ids = FALSE;
- $update_count = 0;
- $where_args = array(
- 'post_type' => array('product', 'product_variation'),
- 'posts_per_page' => -1,
- 'post_status' => 'publish',
- 'suppress_filters' => 1,
- 'fields' => 'id=>parent',
- );
- $where_args['meta_query'] = array();
- $where_args['tax_query'] = array();
- $ofwc_bulk_action_type = !empty($_POST["actionType"]) ? wc_clean($_POST['actionType']) : FALSE;
- $ofwc_bulk_action_target_type = !empty($_POST["actionTargetType"]) ? wc_clean($_POST['actionTargetType']) : FALSE;
- $ofwc_bulk_action_target_where_type = !empty($_POST["actionTargetWhereType"]) ? wc_clean($_POST['actionTargetWhereType']) : FALSE;
- $ofwc_bulk_action_target_where_category = !empty($_POST["actionTargetWhereCategory"]) ? wc_clean($_POST['actionTargetWhereCategory']) : FALSE;
- $ofwc_bulk_action_target_where_product_type = !empty($_POST["actionTargetWhereProductType"]) ? wc_clean($_POST['actionTargetWhereProductType']) : FALSE;
- $ofwc_bulk_action_target_where_price_value = !empty($_POST["actionTargetWherePriceValue"]) ? wc_clean($_POST['actionTargetWherePriceValue']) : FALSE;
- $ofwc_bulk_action_target_where_stock_value = !empty($_POST["actionTargetWhereStockValue"]) ? wc_clean($_POST['actionTargetWhereStockValue']) : FALSE;
- $ofw_meta_key_value = !empty($_POST["ofw_meta_key_value"]) ? wc_clean($_POST['ofw_meta_key_value']) : FALSE;
- $autoAcceptDeclinePercentage = !empty($_POST['autoAcceptDeclinePercentage']) ? wc_clean($_POST['autoAcceptDeclinePercentage']) : FALSE;
-
- if (!$ofwc_bulk_action_type || !$ofwc_bulk_action_target_type) {
- $errors = TRUE;
- }
- if (!$ofw_meta_key_value) {
- $errors = TRUE;
- }
+ public function adminToolBulkEnableDisableCallback() {
+ if (is_admin() && (defined('DOING_AJAX') || DOING_AJAX)) {
+ global $wpdb;
+ $processed_product_id = array();
+ $errors = FALSE;
+ $products = FALSE;
+ $product_ids = FALSE;
+ $update_count = 0;
+ $where_args = array(
+ 'post_type' => array('product', 'product_variation'),
+ 'posts_per_page' => -1,
+ 'post_status' => 'publish',
+ 'suppress_filters' => 1,
+ 'fields' => 'id=>parent',
+ );
+ $where_args['meta_query'] = array();
+ $where_args['tax_query'] = array();
+ $ofwc_bulk_action_type = !empty($_POST["actionType"]) ? wc_clean($_POST['actionType']) : FALSE;
+ $ofwc_bulk_action_target_type = !empty($_POST["actionTargetType"]) ? wc_clean($_POST['actionTargetType']) : FALSE;
+ $ofwc_bulk_action_target_where_type = !empty($_POST["actionTargetWhereType"]) ? wc_clean($_POST['actionTargetWhereType']) : FALSE;
+ $ofwc_bulk_action_target_where_category = !empty($_POST["actionTargetWhereCategory"]) ? wc_clean($_POST['actionTargetWhereCategory']) : FALSE;
+ $ofwc_bulk_action_target_where_product_type = !empty($_POST["actionTargetWhereProductType"]) ? wc_clean($_POST['actionTargetWhereProductType']) : FALSE;
+ $ofwc_bulk_action_target_where_price_value = !empty($_POST["actionTargetWherePriceValue"]) ? wc_clean($_POST['actionTargetWherePriceValue']) : FALSE;
+ $ofwc_bulk_action_target_where_stock_value = !empty($_POST["actionTargetWhereStockValue"]) ? wc_clean($_POST['actionTargetWhereStockValue']) : FALSE;
+ $ofw_meta_key_value = !empty($_POST["ofw_meta_key_value"]) ? wc_clean($_POST['ofw_meta_key_value']) : FALSE;
+ $autoAcceptDeclinePercentage = !empty($_POST['autoAcceptDeclinePercentage']) ? wc_clean($_POST['autoAcceptDeclinePercentage']) : FALSE;
+
+ if (!$ofwc_bulk_action_type || !$ofwc_bulk_action_target_type) {
+ $errors = TRUE;
+ }
+ if (!$ofw_meta_key_value) {
+ $errors = TRUE;
+ }
- $ofwc_bulk_action_type = ($ofwc_bulk_action_type == 'enable' || $ofwc_bulk_action_type == 'enable_onexit' || $ofwc_bulk_action_type == 'accept_enable' || $ofwc_bulk_action_type == 'decline_enable') ? 'yes' : 'no';
+ $ofwc_bulk_action_type = ($ofwc_bulk_action_type == 'enable' || $ofwc_bulk_action_type == 'enable_onexit' || $ofwc_bulk_action_type == 'accept_enable' || $ofwc_bulk_action_type == 'decline_enable') ? 'yes' : 'no';
- // All Products
- if ($ofwc_bulk_action_target_type == 'all') {
- $products = new WP_Query($where_args);
- }
- // Featured products
- elseif ($ofwc_bulk_action_target_type == 'featured') {
- array_push($where_args['tax_query'], array(
- array(
- 'taxonomy' => 'product_visibility',
- 'field' => 'name',
- 'terms' => 'featured',
- )
- )
- );
- $products = new WP_Query($where_args);
- }
- // Where
- elseif ($ofwc_bulk_action_target_type == 'where' && $ofwc_bulk_action_target_where_type) {
- // Where - By Category
- if ($ofwc_bulk_action_target_where_type == 'category' && $ofwc_bulk_action_target_where_category) {
- $where_args['product_cat'] = $ofwc_bulk_action_target_where_category;
- $products = new WP_Query($where_args);
- } // Where - By Product type
- elseif ($ofwc_bulk_action_target_where_type == 'product_type' && $ofwc_bulk_action_target_where_product_type) {
- $where_args['product_type'] = $ofwc_bulk_action_target_where_product_type;
- $products = new WP_Query($where_args);
- } // Where - By Price - greater than
- elseif ($ofwc_bulk_action_target_where_type == 'price_greater') {
- array_push($where_args['meta_query'], array(
- 'key' => '_price',
- 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '>',
- 'type' => 'DECIMAL(10,2)'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - By Price - less than
- elseif ($ofwc_bulk_action_target_where_type == 'price_less') {
- array_push($where_args['meta_query'], array(
- 'key' => '_price',
- 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '<',
- 'type' => 'DECIMAL(10,2)'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - By Stock - greater than
- elseif ($ofwc_bulk_action_target_where_type == 'stock_greater') {
- array_push($where_args['meta_query'], array(
- 'key' => '_manage_stock',
- 'value' => 'yes'
- )
- );
- array_push($where_args['meta_query'], array(
- 'key' => '_stock',
- 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '>',
- 'type' => 'NUMERIC'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - By Stock - less than
- elseif ($ofwc_bulk_action_target_where_type == 'stock_less') {
- array_push($where_args['meta_query'], array(
- 'key' => '_manage_stock',
- 'value' => 'yes'
- )
- );
- array_push($where_args['meta_query'], array(
- 'key' => '_stock',
- 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
- 'compare' => '<',
- 'type' => 'NUMERIC'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - Stock status 'instock'
- elseif ($ofwc_bulk_action_target_where_type == 'instock') {
- array_push($where_args['meta_query'], array(
- 'key' => '_stock_status',
- 'value' => 'instock'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - Stock status 'outofstock'
- elseif ($ofwc_bulk_action_target_where_type == 'outofstock') {
- array_push($where_args['meta_query'], array(
- 'key' => '_stock_status',
- 'value' => 'outofstock'
- )
- );
- $products = new WP_Query($where_args);
- } // Where - Sold Individually
- elseif ($ofwc_bulk_action_target_where_type == 'sold_individually') {
- array_push($where_args['meta_query'], array(
- 'key' => '_sold_individually',
- 'value' => 'yes'
- )
- );
+ // All Products
+ if ($ofwc_bulk_action_target_type == 'all') {
$products = new WP_Query($where_args);
}
- } else {
- $errors = TRUE;
- }
-
- // Update posts
- if (!$errors && $products) {
- if (count($products->posts) < 1) {
- $errors = TRUE;
- $update_count = 'zero';
- $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
- echo $redirect_url;
+ // Featured products
+ elseif ($ofwc_bulk_action_target_type == 'featured') {
+ array_push($where_args['tax_query'], array(
+ array(
+ 'taxonomy' => 'product_visibility',
+ 'field' => 'name',
+ 'terms' => 'featured',
+ )
+ )
+ );
+ $products = new WP_Query($where_args);
+ }
+ // Where
+ elseif ($ofwc_bulk_action_target_type == 'where' && $ofwc_bulk_action_target_where_type) {
+ // Where - By Category
+ if ($ofwc_bulk_action_target_where_type == 'category' && $ofwc_bulk_action_target_where_category) {
+ $where_args['product_cat'] = $ofwc_bulk_action_target_where_category;
+ $products = new WP_Query($where_args);
+ } // Where - By Product type
+ elseif ($ofwc_bulk_action_target_where_type == 'product_type' && $ofwc_bulk_action_target_where_product_type) {
+ $where_args['product_type'] = $ofwc_bulk_action_target_where_product_type;
+ $products = new WP_Query($where_args);
+ } // Where - By Price - greater than
+ elseif ($ofwc_bulk_action_target_where_type == 'price_greater') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_price',
+ 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '>',
+ 'type' => 'DECIMAL(10,2)'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - By Price - less than
+ elseif ($ofwc_bulk_action_target_where_type == 'price_less') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_price',
+ 'value' => number_format($ofwc_bulk_action_target_where_price_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '<',
+ 'type' => 'DECIMAL(10,2)'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - By Stock - greater than
+ elseif ($ofwc_bulk_action_target_where_type == 'stock_greater') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_manage_stock',
+ 'value' => 'yes'
+ )
+ );
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock',
+ 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '>',
+ 'type' => 'NUMERIC'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - By Stock - less than
+ elseif ($ofwc_bulk_action_target_where_type == 'stock_less') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_manage_stock',
+ 'value' => 'yes'
+ )
+ );
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock',
+ 'value' => number_format($ofwc_bulk_action_target_where_stock_value, wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()),
+ 'compare' => '<',
+ 'type' => 'NUMERIC'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - Stock status 'instock'
+ elseif ($ofwc_bulk_action_target_where_type == 'instock') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock_status',
+ 'value' => 'instock'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - Stock status 'outofstock'
+ elseif ($ofwc_bulk_action_target_where_type == 'outofstock') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_stock_status',
+ 'value' => 'outofstock'
+ )
+ );
+ $products = new WP_Query($where_args);
+ } // Where - Sold Individually
+ elseif ($ofwc_bulk_action_target_where_type == 'sold_individually') {
+ array_push($where_args['meta_query'], array(
+ 'key' => '_sold_individually',
+ 'value' => 'yes'
+ )
+ );
+ $products = new WP_Query($where_args);
+ }
} else {
- foreach ($products->posts as $target) {
- $target_product_id = ( $target->post_parent != '0' ) ? $target->post_parent : $target->ID;
- if (get_post_type($target_product_id) == 'product' && !in_array($target_product_id, $processed_product_id)) {
- if (!update_post_meta($target_product_id, $ofw_meta_key_value, $ofwc_bulk_action_type)) {
-
- } else {
- $processed_product_id[$target_product_id] = $target_product_id;
- }
- if ($autoAcceptDeclinePercentage) {
- $ofw_auto_accept_or_decline_percentage_key = str_replace("enabled", "percentage", $ofw_meta_key_value);
- update_post_meta($target_product_id, $ofw_auto_accept_or_decline_percentage_key, $autoAcceptDeclinePercentage);
- $processed_product_id[$target_product_id] = $target_product_id;
+ $errors = TRUE;
+ }
+
+ // Update posts
+ if (!$errors && $products) {
+ if (count($products->posts) < 1) {
+ $errors = TRUE;
+ $update_count = 'zero';
+ $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
+ echo $redirect_url;
+ } else {
+ foreach ($products->posts as $target) {
+ $target_product_id = ( $target->post_parent != '0' ) ? $target->post_parent : $target->ID;
+ if (get_post_type($target_product_id) == 'product' && !in_array($target_product_id, $processed_product_id)) {
+ if (!update_post_meta($target_product_id, $ofw_meta_key_value, $ofwc_bulk_action_type)) {
+
+ } else {
+ $processed_product_id[$target_product_id] = $target_product_id;
+ }
+ if ($autoAcceptDeclinePercentage) {
+ $ofw_auto_accept_or_decline_percentage_key = str_replace("enabled", "percentage", $ofw_meta_key_value);
+ update_post_meta($target_product_id, $ofw_auto_accept_or_decline_percentage_key, $autoAcceptDeclinePercentage);
+ $processed_product_id[$target_product_id] = $target_product_id;
+ }
}
}
+ $update_count = count($processed_product_id);
}
- $update_count = count($processed_product_id);
}
- }
- // return
- if (!$errors) {
- if ($update_count == 0) {
- $update_count = 'zero';
- }
+ // return
+ if (!$errors) {
+ if ($update_count == 0) {
+ $update_count = 'zero';
+ }
- $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
- echo $redirect_url;
- } else {
- //echo 'failed';
+ $redirect_url = admin_url('options-general.php?page=offers-for-woocommerce&tab=tools&processed=' . $update_count);
+ echo $redirect_url;
+ } else {
+ //echo 'failed';
+ }
+ die(); // this is required to return a proper result
}
- die(); // this is required to return a proper result
}
- }
- /**
- * Add a custom email to the list of emails WooCommerce should load
- *
- * @since 0.1
- * @param array $email_classes available email classes
- * @return array filtered available email classes
- */
- public function add_woocommerce_email_classes($email_classes) {
-
- // include our custom email classes
- require( 'includes/class-wc-accepted-offer-email.php' );
- require( 'includes/class-wc-declined-offer-email.php' );
- require( 'includes/class-wc-countered-offer-email.php' );
- require( 'includes/class-wc-offer-on-hold-email.php' );
- require( 'includes/class-wc-offer-note-email.php' );
- require( 'includes/class-wc-open-offer-email.php' );
-
- // add the email class to the list of email classes that WooCommerce loads
- $email_classes['WC_Accepted_Offer_Email'] = new WC_Accepted_Offer_Email();
- $email_classes['WC_Declined_Offer_Email'] = new WC_Declined_Offer_Email();
- $email_classes['WC_Countered_Offer_Email'] = new WC_Countered_Offer_Email();
- $email_classes['WC_Offer_On_Hold_Email'] = new WC_Offer_On_Hold_Email();
- $email_classes['WC_Offer_Note_Email'] = new WC_Offer_Note_Email();
- $email_classes['WC_Open_Offer_Email'] = new WC_Open_Offer_Email();
-
- return $email_classes;
- }
+ /**
+ * Add a custom email to the list of emails WooCommerce should load
+ *
+ * @since 0.1
+ * @param array $email_classes available email classes
+ * @return array filtered available email classes
+ */
+ public function add_woocommerce_email_classes($email_classes) {
+
+ // include our custom email classes
+ require( 'includes/class-wc-accepted-offer-email.php' );
+ require( 'includes/class-wc-declined-offer-email.php' );
+ require( 'includes/class-wc-countered-offer-email.php' );
+ require( 'includes/class-wc-offer-on-hold-email.php' );
+ require( 'includes/class-wc-offer-note-email.php' );
+ require( 'includes/class-wc-open-offer-email.php' );
+
+ // add the email class to the list of email classes that WooCommerce loads
+ $email_classes['WC_Accepted_Offer_Email'] = new WC_Accepted_Offer_Email();
+ $email_classes['WC_Declined_Offer_Email'] = new WC_Declined_Offer_Email();
+ $email_classes['WC_Countered_Offer_Email'] = new WC_Countered_Offer_Email();
+ $email_classes['WC_Offer_On_Hold_Email'] = new WC_Offer_On_Hold_Email();
+ $email_classes['WC_Offer_Note_Email'] = new WC_Offer_Note_Email();
+ $email_classes['WC_Open_Offer_Email'] = new WC_Open_Offer_Email();
+
+ return $email_classes;
+ }
- /**
- * Add WP Notices
- * @since 0.1.0
- */
- public function aeofwc_admin_notices() {
- global $current_user;
- $user_id = $current_user->ID;
+ /**
+ * Add WP Notices
+ * @since 0.1.0
+ */
+ public function aeofwc_admin_notices() {
+ global $current_user;
+ $user_id = $current_user->ID;
- $screen = get_current_screen();
+ $screen = get_current_screen();
- // if filtering Offers edit page by 'author'
- if ("edit-woocommerce_offer" == $screen->id && is_admin()) {
- $author_id = (isset($_GET['author']) && is_numeric($_GET['author'])) ? wc_clean($_GET['author']) : '';
- if ($author_id) {
- $author_data = get_userdata($author_id);
- // not valid user id
- if (!$author_data)
- return;
+ // if filtering Offers edit page by 'author'
+ if ("edit-woocommerce_offer" == $screen->id && is_admin()) {
+ $author_id = (isset($_GET['author']) && is_numeric($_GET['author'])) ? wc_clean($_GET['author']) : '';
+ if ($author_id) {
+ $author_data = get_userdata($author_id);
+ // not valid user id
+ if (!$author_data)
+ return;
- echo '';
+ echo '';
+ }
}
- }
- if ($this->plugin_screen_hook_suffix == $screen->id && is_admin()) {
+ if ($this->plugin_screen_hook_suffix == $screen->id && is_admin()) {
- // Tools - Bulk enable/disable offers
- $processed = (isset($_GET['processed']) ) ? wc_clean($_GET['processed']) : FALSE;
- if ($processed) {
- if ($processed == 'zero') {
- echo '';
- echo '
' . sprintf(__('Action completed; %s records processed.', 'offers-for-woocommerce'), '0');
- echo '
';
- } else {
- echo '';
- echo '
' . sprintf(__('Action completed; %s records processed. ', 'offers-for-woocommerce'), $processed);
- echo '
';
+ // Tools - Bulk enable/disable offers
+ $processed = (isset($_GET['processed']) ) ? wc_clean($_GET['processed']) : FALSE;
+ if ($processed) {
+ if ($processed == 'zero') {
+ echo '';
+ echo '
' . sprintf(__('Action completed; %s records processed.', 'offers-for-woocommerce'), '0');
+ echo '
';
+ } else {
+ echo '';
+ echo '
' . sprintf(__('Action completed; %s records processed. ', 'offers-for-woocommerce'), $processed);
+ echo '
';
+ }
}
}
- }
- /**
- * Detect other known plugins that might conflict; show warnings
- */
- if (is_plugin_active('social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php')) {
- // Check that the user hasn't already clicked to ignore the message
- if (!get_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_next_scripts_snap')) {
- $get_symbol = (strpos($_SERVER['REQUEST_URI'], "?")) ? "&" : "?";
- echo ' ' . __('We notice you are running the NextScripts Social Networks Auto-Poster plugin.', 'offers-for-woocommerce') . ' ' . __('Please make sure to exclude the custom post type "woocommerce_offer" in the {SNAP} Social Networks Auto-Poster settings in order to avoid conflicts with new offers.', 'offers-for-woocommerce') . ' | Hide Notice
';
+ /**
+ * Detect other known plugins that might conflict; show warnings
+ */
+ if (is_plugin_active('social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php')) {
+ // Check that the user hasn't already clicked to ignore the message
+ if (!get_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_next_scripts_snap')) {
+ $get_symbol = (strpos($_SERVER['REQUEST_URI'], "?")) ? "&" : "?";
+ echo ' ' . __('We notice you are running the NextScripts Social Networks Auto-Poster plugin.', 'offers-for-woocommerce') . ' ' . __('Please make sure to exclude the custom post type "woocommerce_offer" in the {SNAP} Social Networks Auto-Poster settings in order to avoid conflicts with new offers.', 'offers-for-woocommerce') . ' | Hide Notice
';
+ }
}
- }
- return;
- }
+ return;
+ }
- /**
- * Adds help tab content for manage offer screen
- * @param $contextual_help
- * @param $screen_id
- * @param $screen
- * @return mixed
- */
- function ae_ofwc_contextual_help() {
- $screen = get_current_screen();
- // Only add to certain screen(s). The add_help_tab function for screen was introduced in WordPress 3.3.
+ /**
+ * Adds help tab content for manage offer screen
+ * @param $contextual_help
+ * @param $screen_id
+ * @param $screen
+ * @return mixed
+ */
+ function ae_ofwc_contextual_help() {
+ $screen = get_current_screen();
+ // Only add to certain screen(s). The add_help_tab function for screen was introduced in WordPress 3.3.
- if (!$screen || "woocommerce_offer" != $screen->id) {
- return;
+ if (!$screen || "woocommerce_offer" != $screen->id) {
+ return;
+ }
+ $content = ''
+ . '' . sprintf('%s ', 'https://www.angelleye.com/offers-woocommerce-install-setup-guide/', 'Install Guide') . ' '
+ . '' . sprintf('%s ', 'https://www.angelleye.com/offers-for-woocommerce-user-guide/', 'User Guide') . ' '
+ . '' . sprintf('%s ', 'https://www.angelleye.com/offers-for-woocommerce-developer-hooks-guide/', 'Developer Hooks Guide') . ' '
+ . ' ';
+ $screen->add_help_tab(array(
+ 'id' => 'angelleye-offers-for-woocommerce-overview-tab_01',
+ 'title' => __('Documentation', 'offers-for-woocommerce'),
+ 'content' => $content,
+ ));
}
- $content = ''
- . '' . sprintf('%s ', 'https://www.angelleye.com/offers-woocommerce-install-setup-guide/', 'Install Guide') . ' '
- . '' . sprintf('%s ', 'https://www.angelleye.com/offers-for-woocommerce-user-guide/', 'User Guide') . ' '
- . '' . sprintf('%s ', 'https://www.angelleye.com/offers-for-woocommerce-developer-hooks-guide/', 'Developer Hooks Guide') . ' '
- . ' ';
- $screen->add_help_tab(array(
- 'id' => 'angelleye-offers-for-woocommerce-overview-tab_01',
- 'title' => __('Documentation', 'offers-for-woocommerce'),
- 'content' => $content,
- ));
- }
- /*
- * Check WooCommerce is available
- * @since 0.1.0
- */
+ /*
+ * Check WooCommerce is available
+ * @since 0.1.0
+ */
- public function ae_ofwc_check_woocommerce_available() {
- if (is_admin()) {
+ public function ae_ofwc_check_woocommerce_available() {
+ if (is_admin()) {
- global $current_user;
- $user_id = $current_user->ID;
+ global $current_user;
+ $user_id = $current_user->ID;
- if (!function_exists('WC')) {
- if (class_exists('Angelleye_Offers_For_Woocommerce')) {
+ if (!function_exists('WC')) {
+ if (class_exists('Angelleye_Offers_For_Woocommerce')) {
- // deactivate offers for woocommerce plugin
- deactivate_plugins(plugin_dir_path(realpath(dirname(__FILE__))) . 'offers-for-woocommerce.php');
+ // deactivate offers for woocommerce plugin
+ deactivate_plugins(plugin_dir_path(realpath(dirname(__FILE__))) . 'offers-for-woocommerce.php');
+ // remove hide nag msg
+ //delete_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01');
+ // redirect
+ //wp_redirect('plugins.php');
+ }
+ add_action('admin_notices', array($this, 'ae_ofwc_admin_notice_woocommerce_mia'));
+ } else {
// remove hide nag msg
- //delete_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01');
- // redirect
- //wp_redirect('plugins.php');
+ delete_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01');
}
- add_action('admin_notices', array($this, 'ae_ofwc_admin_notice_woocommerce_mia'));
- } else {
- // remove hide nag msg
- delete_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01');
}
}
- }
- public function ae_ofwc_admin_notice_woocommerce_mia() {
- global $current_user;
- $user_id = $current_user->ID;
+ public function ae_ofwc_admin_notice_woocommerce_mia() {
+ global $current_user;
+ $user_id = $current_user->ID;
- // Check that the user hasn't already clicked to ignore the message
- if (!get_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01')) {
- printf('', __('Offers for WooCommerce has been deactivated; WooCommerce is required. Please make sure that WooCommerce is installed and activated before activating Offers for WooCommerce.', 'offers-for-woocommerce'), '?angelleye_offers_for_woocommerce_ignore_01=0');
+ // Check that the user hasn't already clicked to ignore the message
+ if (!get_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01')) {
+ printf('', __('Offers for WooCommerce has been deactivated; WooCommerce is required. Please make sure that WooCommerce is installed and activated before activating Offers for WooCommerce.', 'offers-for-woocommerce'), '?angelleye_offers_for_woocommerce_ignore_01=0');
+ }
}
- }
- /**
- * Add ignore nag message for admin notices
- * @since 0.1.0
- */
- public function ae_ofwc_check_woocommerce_nag_notice_ignore() {
- global $current_user;
- $user_id = $current_user->ID;
+ /**
+ * Add ignore nag message for admin notices
+ * @since 0.1.0
+ */
+ public function ae_ofwc_check_woocommerce_nag_notice_ignore() {
+ global $current_user;
+ $user_id = $current_user->ID;
- /* If user clicks to ignore the notice, add that to their user meta */
- if (isset($_GET['angelleye_offers_for_woocommerce_ignore_01']) && '0' == $_GET['angelleye_offers_for_woocommerce_ignore_01']) {
- add_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01', 'true');
- }
+ /* If user clicks to ignore the notice, add that to their user meta */
+ if (isset($_GET['angelleye_offers_for_woocommerce_ignore_01']) && '0' == $_GET['angelleye_offers_for_woocommerce_ignore_01']) {
+ add_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_01', 'true');
+ }
- /* If user clicks to ignore the notice, add that to their user meta */
- if (isset($_GET['angelleye_offers_for_woocommerce_ignore_next_scripts_snap']) && '0' == $_GET['angelleye_offers_for_woocommerce_ignore_next_scripts_snap']) {
- add_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_next_scripts_snap', 'true');
+ /* If user clicks to ignore the notice, add that to their user meta */
+ if (isset($_GET['angelleye_offers_for_woocommerce_ignore_next_scripts_snap']) && '0' == $_GET['angelleye_offers_for_woocommerce_ignore_next_scripts_snap']) {
+ add_user_meta($user_id, 'angelleye_offers_for_woocommerce_ignore_next_scripts_snap', 'true');
+ }
}
- }
- /**
- * Action - Bulk action - Enable/Disable Offers on WooCommerce products
- * @since 1.0.1
- */
- public function custom_bulk_admin_footer() {
+ /**
+ * Action - Bulk action - Enable/Disable Offers on WooCommerce products
+ * @since 1.0.1
+ */
+ public function custom_bulk_admin_footer() {
- global $post_type;
+ global $post_type;
- if ($post_type == 'product') {
- ?>
+ if ($post_type == 'product') {
+ ?>
+