-
-
Save albertpak/7048599 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| function display_dynamic_pricing_table(){ | |
| global $post; | |
| # see line 42 of woocommerce_pricing_by_product.class.php | |
| $pricing_rule_sets = get_option('_a_category_pricing_rules', array()); | |
| $found = false; | |
| if(count($pricing_rule_sets)){ | |
| global $woocommerce_pricing; | |
| foreach ($pricing_rule_sets as $pricing_rule_set) { | |
| // check for category | |
| $collector = isset($pricing_rule_set['collector']) ? $pricing_rule_set['collector'] : array(); | |
| if($collector){ | |
| if($collector['type'] == 'cat_product'){ | |
| $in = false; | |
| foreach($collector['args']['cats'] as $cat){ | |
| if(has_term($cat, 'product_cat', $post->ID)) $in = true; | |
| } | |
| if(!$in) continue; | |
| } | |
| } | |
| $pricing_rule_sets = array(array('rules' => $pricing_rule_set['rules'])); | |
| $found = true; | |
| break; | |
| } | |
| } | |
| if(!$found){ | |
| $pricing_rule_sets = NULL; | |
| } | |
| $product_pricing_rule_sets = get_post_meta($post->ID, '_pricing_rules', true); | |
| if($product_pricing_rule_sets){ | |
| $pricing_rule_sets = $product_pricing_rule_sets; | |
| } | |
| if(count($pricing_rule_sets)){ | |
| $pricing = ''; | |
| foreach($pricing_rule_sets as $ruleset){ | |
| $rules = $ruleset['rules']; | |
| foreach($rules as $rule){ | |
| $pricing .= '<tr>'; | |
| $pricing .= '<td class="col1">'.$rule['from']; | |
| $pricing .= $rule['to'] ? ' - '.$rule['to'] : '+'; | |
| $pricing .= '</td>'; | |
| $pricing .= '<td>$'. number_format($rule['amount'], 2).'</td>'; | |
| $pricing .= '</tr>'; | |
| } | |
| } | |
| if($pricing){ | |
| $output = <<<DYNAMICPRICING | |
| <div class="dynamic-pricing"> | |
| <table class="pricing-table"> | |
| <thead> | |
| <tr> | |
| <th class="col1">quantity</th> | |
| <th>price</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| $pricing | |
| </tbody> | |
| </table> | |
| </div><!-- .dynamic-pricing --> | |
| DYNAMICPRICING; | |
| echo $output; | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for WooCommerce Dynamic Pricing
To display pricing table on product page: