Last active
August 16, 2021 08:41
-
-
Save greguly/7212457 to your computer and use it in GitHub Desktop.
Woocommerce Dynamic Pricing table price view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
?> |
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!!
@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;
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
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