Skip to content

Commit d460ea3

Browse files
authored
Merge pull request #513 from angelleye/OFW-302
OFW-302 - Resolved the percentage calculation error and frontend price check issue
2 parents 6a59efd + a0f5fd4 commit d460ea3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

public/assets/js/public.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -324,25 +324,25 @@ document.addEventListener("DOMContentLoaded", function (event) {
324324
} else if (productType === 'simple') {
325325
if( undefined !== priceField && null !== priceField ) {
326326
offerProductPrice = priceField.querySelector('.amount').textContent;
327-
} else if( undefined !== priceBlockField ) {
327+
} else if( undefined !== priceBlockField && null !== priceBlockField) {
328328
offerProductPrice = priceBlockField.querySelector('.amount').textContent;
329329
}
330330
} else if (productType === 'sale_product') {
331331
if( undefined !== priceField && null !== priceField) {
332332
offerProductPrice = priceField.querySelector('ins').textContent;
333-
} else if( undefined !== priceBlockField ) {
333+
} else if( undefined !== priceBlockField && null !== priceBlockField ) {
334334
offerProductPrice = priceBlockField.querySelector('ins').textContent;
335335
}
336336
} else if (productType === 'grouped') {
337337
if( undefined !== priceField && null !== priceField ) {
338338
offerProductPrice = priceField.querySelector('.amount').textContent;
339-
} else if( undefined !== priceBlockField ) {
339+
} else if( undefined !== priceBlockField && null !== priceBlockField) {
340340
offerProductPrice = priceBlockField.querySelector('.amount').textContent;
341341
}
342342
} else if (productType === 'external') {
343343
if( undefined !== priceField && null !== priceField ) {
344344
offerProductPrice = priceField.querySelector('.amount').textContent;
345-
} else if( undefined !== priceBlockField ) {
345+
} else if( undefined !== priceBlockField && null !== priceBlockField ) {
346346
offerProductPrice = priceBlockField.querySelector('.amount').textContent;
347347
}
348348
} else {

public/class-offers-for-woocommerce.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function __construct() {
9696
*/
9797
add_action('wp_ajax_new_offer_form_submit', array($this, 'new_offer_form_submit'));
9898
add_action('wp_ajax_nopriv_new_offer_form_submit', array($this, 'new_offer_form_submit'));
99-
99+
100100
/* Add "Make Offer" button code parts - Before add to cart */
101101
add_action('woocommerce_before_add_to_cart_button', array($this, 'angelleye_ofwc_before_add_to_cart_button'));
102102
add_action('woocommerce_after_add_to_cart_form', array($this, 'angelleye_ofwc_after_add_to_cart_form'));
@@ -3400,10 +3400,13 @@ public function ofwc_get_product_detail($offer_id, $product_id, $variant_id) {
34003400

34013401
$product_price = (isset($actual_sales_price) && !empty($actual_sales_price)) ? $actual_sales_price : $actual_regular_price;
34023402
$productData['offer_price'] = $offer_price = get_post_meta($offer_id, 'offer_price_per', true);
3403-
$productData['user_offer_percentage'] = $user_offer_percentage = $this->ofwc_get_percentage($offer_price, $product_price);
3403+
$productData['user_offer_percentage'] = 0;
3404+
if ($product_price > 0) {
3405+
$productData['user_offer_percentage'] = $this->ofwc_get_percentage($offer_price, $product_price);
3406+
}
34043407
$product = ( $variant_id ) ? wc_get_product($variant_id) : wc_get_product($product_id);
3405-
$productData['product_url'] = $product_url = $product->get_permalink();
3406-
$productData['offer_uid'] = $offer_uid = get_post_meta($offer_id, 'offer_uid', true);
3408+
$productData['product_url'] = $product->get_permalink();
3409+
$productData['offer_uid'] = get_post_meta($offer_id, 'offer_uid', true);
34073410

34083411
return $productData;
34093412
}

0 commit comments

Comments
 (0)