Woocommerce with Dynamic Pricing get all dynamic prices

For those that want the code on how to get the array of the dynamic prices : <?php //global $post, $product; // Must Have //$meta = get_post_meta($product->id); //$rules = $meta['_pricing_rules'][0]; //var_dump(unserialize($rules)); function woocommerce_price_chart() { global $post, $product; $meta = get_post_meta($post->ID); $rules = $meta['_pricing_rules'][0]; $clean_rules = unserialize($rules); $new_rules =reset($clean_rules); $string = ''; $string .= '<div class="pricing-table table">'; $string .= '<div class="table-row">'; $string .= '<div class="table-cell">Number of Items</div>'; $string .= '<div class="table-cell">Price</div>'; $string .= '</div>'; for ($i=1; $i < count($new_rules['rules']); $i++) { $string .= '<div class="table-row">'; $string .= '<div class="table-cell">'. $new_rules['rules'][$i]['from'] .' - '. $new_rules['rules'][$i]['to'] .'</div>'; $string .= '<div class="table-cell">'. $new_rules['rules'][$i]['amount'] .'</div>'; $string .= '</div>'; } $string .= '</div>'; echo $string; }
For those that want the code on how to get the array of the dynamic prices .
Requires the Woocommerce Dynamic Pricing plugin for Woocommerce.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.