lhenning
Forum Replies Created
-
We do have WPS hide login.
Does this cause the problem or when hackers can’t find wp-admin they go looking for it?
Forum: Plugins
In reply to: [WooCommerce Bulk Discount] show discount infoI fixed it so that it doesn’t display on admin pages and this code will work in functions.php
add_filter( 'woocommerce_get_price_html', 'filter_get_price_html', 10, 2); /** * Hook to woocommerce_get_price_html filter. * * @param $price * @param $_product * @return string */ function filter_get_price_html( $price , $_product) { if ( !$_product ) { return $price; } if (is_admin()){ return $price; } global $woocommerce; if ( get_option( 'woocommerce_t4m_remove_discount_on_coupon', 'yes' ) == 'yes' && !( empty( $woocommerce->cart->applied_coupons ) )) { return $price; } /* if ( $this->coupon_check() ) { return $price; } */ if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) { return $price; } $bulkDiscountType = get_option( 'woocommerce_t4m_discount_type', '' ); /* if ($bulkDiscountType == 'flat'){ echo '<p>Flat bulk discount</p>'; } else if ($bulkDiscountType == 'fixed') { echo '<p>Fixed bulk discount</p>'; } else { echo '<p>Percentage bulk discount</p>'; } */ //get the array of discounts $origPrice = $_product->get_price(); //echo "<p>original Price = $origPrice </p>"; $q = array( 0.0 ); $d = array( 0.0 ); $priceList = array(0.0); $foundPriceBreak = FALSE; $product_id = $_product->get_id(); //echo "<p>product ID = $product_id </p>"; /* get all the possible discounts */ for ( $i = 1; $i <= 5; $i++ ) { array_push( $q, get_post_meta( $product_id, "_bulkdiscount_quantity_$i", true ) ); if ( $bulkDiscountType == 'flat' ) { array_push( $priceList, get_post_meta( $product_id, "_bulkdiscount_discount_flat_$i", true ) ? get_post_meta( $product_id, "_bulkdiscount_discount_flat_$i", true ) : 0.0 ); } else if ( $bulkDiscountType == 'fixed' ) { array_push( $d, get_post_meta( $product_id, "_bulkdiscount_discount_fixed_$i", true ) ? get_post_meta( $product_id, "_bulkdiscount_discount_fixed_$i", true ) : 0.0 ); array_push( $priceList, $origPrice - $d[$i] ); } else { array_push( $d, get_post_meta( $product_id, "_bulkdiscount_discount_$i", true ) ? get_post_meta( $product_id, "_bulkdiscount_discount_$i", true ) : 0.0 ); array_push( $priceList, $origPrice * min( 1.0, max( 0, ( 100.0 - round( $d[$i], 2 ) ) / 100.0 ) )); } } $priceTable = <<<TABLEOPEN <table class="woocommerce-bulk-pricing-table"> <tr> <th>Quantity</th> <th>Price</th> </tr> <tr> <td>1</td> <td>$price</td> </tr> TABLEOPEN; for ( $j = 1; $j <= 5; $j++ ) { if ($q[$j] > 0.0) { $foundPriceBreak = TRUE; $priceTable .="<tr>\n"; $priceTable .="<td>$q[$j]</td>\n"; $priceTable .="<td>".wc_price($priceList[$j]); if ($bulkDiscountType == 'flat'){ $priceTable .=" rebate"; } $priceTable .="</td>\n"; $priceTable .="</tr>\n"; } } $priceTable .="</table>\n"; if ($foundPriceBreak){ return $priceTable; } return $price; }
Forum: Plugins
In reply to: [WooCommerce Bulk Discount] show discount infoI did make it work for fixed and flat but not sure if I got them correct I just haven’t tested. I assumed that fixed meant you specify the price above a certain quantity. e.g. 1 = $2.00 10 = $1.83
flat was once you reached a certain quantity you got money back e.g. 10$ off if you buy 100If the creator is OK with my code, I am willing to put in the work to add this feature properly into the plugin.
Leo
Not sure exactly what you mean but I put a post here. Might be close to what you are looking for.
Forum: Plugins
In reply to: [WooCommerce Bulk Discount] show discount infoThere are a bunch of ways to do it but I added a filter on the get_price_html
Here is my code which I have tested for the percentage option not fixed or flat.
Should give you the basic idea.
I edited the Bulk Discount plugin directly which is probably not advisable. should put it in a separate plugin.
add_filter( 'woocommerce_get_price_html', array( $this, 'filter_get_price_html' ), 10, 2);
/** * Hook to woocommerce_get_price_html filter. * * @param $price * @param $_product * @return string */ public function filter_get_price_html( $price , $_product) { if ( !$_product ) { return $price; } if ( $this->coupon_check() ) { return $price; } if ( get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) != '' && get_post_meta( $_product->id, "_bulkdiscount_enabled", true ) !== 'yes' ) { return $price; } $bulkDiscountType = get_option( 'woocommerce_t4m_discount_type', '' ); /* if ($bulkDiscountType == 'flat'){ echo '<p>Flat bulk discount</p>'; } else if ($bulkDiscountType == 'fixed') { echo '<p>Fixed bulk discount</p>'; } else { echo '<p>Percentage bulk discount</p>'; } */ //get the array of discounts $origPrice = $_product->get_price(); //echo "<p>original Price = $origPrice </p>"; $q = array( 0.0 ); $d = array( 0.0 ); $priceList = array(0.0); $product_id = $_product->get_id(); //echo "<p>product ID = $product_id </p>"; /* get all the possible discounts */ for ( $i = 1; $i <= 5; $i++ ) { array_push( $q, get_post_meta( $product_id, "_bulkdiscount_quantity_$i", true ) ); if ( $bulkDiscountType == 'flat' ) { array_push( $priceList, get_post_meta( $product_id, "_bulkdiscount_discount_flat_$i", true ) ? get_post_meta( $product_id, "_bulkdiscount_discount_flat_$i", true ) : 0.0 ); } else if ( $bulkDiscountType == 'fixed' ) { array_push( $d, get_post_meta( $product_id, "_bulkdiscount_discount_fixed_$i", true ) ? get_post_meta( $product_id, "_bulkdiscount_discount_fixed_$i", true ) : 0.0 ); array_push( $priceList, $origPrice - $d[$i] ); } else { array_push( $d, get_post_meta( $product_id, "_bulkdiscount_discount_$i", true ) ? get_post_meta( $product_id, "_bulkdiscount_discount_$i", true ) : 0.0 ); array_push( $priceList, $origPrice * min( 1.0, max( 0, ( 100.0 - round( $d[$i], 2 ) ) / 100.0 ) )); } } $priceTable = <<<TABLEOPEN <table class="woocommerce-bulk-pricing-table"> <tr> <th>Quantity</th> <th>Price</th> </tr> <tr> <td>1</td> <td>$price</td> </tr> TABLEOPEN; for ( $j = 1; $j <= 5; $j++ ) { if ($q[$j] > 0.0) { $priceTable .="<tr>\n"; $priceTable .="<td>$q[$j]</td>\n"; $priceTable .="<td>".wc_price($priceList[$j]); if ($bulkDiscountType == 'flat'){ $priceTable .=" rebate"; } $priceTable .="</td>\n"; $priceTable .="</tr>\n"; } } $priceTable .="</table>\n"; return $priceTable; }