Skip to content

Instantly share code, notes, and snippets.

@greguly
Last active August 16, 2021 08:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greguly/7212457 to your computer and use it in GitHub Desktop.
Save greguly/7212457 to your computer and use it in GitHub Desktop.
Woocommerce Dynamic Pricing table price view
add_filter( 'woocommerce_get_price_html', 'omniwp_credit_dollars_price', 10, 2 );
function omniwp_credit_dollars_price( $price, $product ) {
$pricing_rule_sets = get_post_meta( $product->post->ID, '_pricing_rules', true );
$pricing_rule_sets = array_shift( $pricing_rule_sets );
if ( $pricing_rule_sets
&& is_array( $pricing_rule_sets )
&& sizeof( $pricing_rule_sets ) ) {
ob_start();
?>
<table>
<thead>
<tr>
<th><?php _e('Quantity', 'omniwp_core_functionality' ) ?></th>
<th><?php _e('Price', 'omniwp_core_functionality' ) ?></th>
</tr>
</thead>
<?php
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
if ( '*' == $pricing_rule_sets['rules'][$key]['to'] ) {
?>
<tr>
<td><?php printf( __( '%s units or more', 'omniwp_core_functionality' ) , $pricing_rule_sets['rules'][$key]['from'] ) ?></td>
<td><?php echo woocommerce_price( $pricing_rule_sets['rules'][$key]['amount'] ); ?></td>
</tr>
<?php
} else {
?>
<tr>
<td><?php printf( __( 'From %s to %s units', 'omniwp_core_functionality' ) , $pricing_rule_sets['rules'][$key]['from'], $pricing_rule_sets['rules'][$key]['to'] ) ?></td>
<td><?php echo woocommerce_price( $pricing_rule_sets['rules'][$key]['amount'] ); ?></td>
</tr>
<?php
}
}
?>
</table>
<?php
$price = ob_get_clean();
}
return $price;
}
?>
@ladnie
Copy link

ladnie commented May 9, 2014

Hello,

I'm using this code:

add_filter( 'init', 'wc_tax_exempt_user_roles' );
function wc_tax_exempt_user_roles() {
if ( ! is_admin() ) {
global $woocommerce;
if ( current_user_can('wholesale') ) {
$woocommerce->customer->set_is_vat_exempt(true);
} else {
$woocommerce->customer->set_is_vat_exempt(false);
}
}
}

to disable taxes for wholesale buyers - this is how it works in EU.
And using Dynamic Pricing, prices in catalog are always displayed with tax (using 0rules). Do you know how to fix it?
Thanks

@johnzhel
Copy link

johnzhel commented Aug 2, 2016

@greguly
I tried your code and found 2 issues.

  1. This does not work with percentage % discount set in dynamic pricing
  2. This make variable product's pricing show an warning/error. (I have different prices for different variations. )
    Can you take a look? Thanks!

@pamolade
Copy link

pamolade commented Dec 7, 2017

Hi!

We use commas for decimal seperators, but this plugin wont accept that, and only shows 00 (zeros) as decimals, even though other number should be there. What do i do?

@fcariboni
Copy link

Hi,
i used your code and it's work, but when the interval date of the dynamic price rule is over, I would not show the table. It’s possible?

Thank you

@eiertee
Copy link

eiertee commented Feb 5, 2018

Thx for this! Quick question : the provided code also forces showing the table on the product catalogue page - how can we keep the table showing on single product page only? Thank you!!

@senoux
Copy link

senoux commented Mar 31, 2021

@pamolade for decimals correct, i change on line 235 to:
case 'fixed_price':
$output .= '' . sprintf( $pricing_rule_sets['rules'][$key]['amount'] ) . __( ' Per item', 'woocommerce-dynamic-pricing-table' ) . '';
break;

@greguly
Copy link
Author

greguly commented Mar 31, 2021

Hiya,

I am amazed that this piece of code was used by others.

Where do you see line 235 @senoux?

Cheers,
Gabriel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment