Plugin Directory

Opened 6 years ago

#2768 new defect

Changes for fixed_price and percentage_discount support

Reported by: wpsilver's profile wpsilver's profile wpsilver Owned by:
Priority: normal Severity: normal
Plugin: not-listed Keywords:
Cc:

Description

Hello,

Sorry don't know how to commit or send pull request, could you please update the plugin?
Thank you

wc-pricing-table-template.php

<?php
$output = '<table class="wc-bulk-pricing-table">';

$output .= '<th>' . __( $qty_label, 'wc-pricing-table' ) . '</th><th>' . __( $discount_type_label, 'wc-pricing-table' ) . '</th>';

foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
        if ( $pricing_rule_sets['rules'][ $key ]['type'] == 'price_discount' ||
             $pricing_rule_sets['rules'][ $key ]['type'] == 'fixed_price' ||
             $pricing_rule_sets['rules'][ $key ]['type'] == 'percentage_discount' ) {
                // Checks if a product discount group max quantity field is less than 1.
                if ( $pricing_rule_sets['rules'][ $key ]['to'] < 1 ) {
                        $rules_to = __( ' или больше', 'wc-pricing-table' );
                } else {
                        $rules_to = ' - ' . wc_stock_amount( $pricing_rule_sets['rules'][ $key ]['to'] );
                }

                $output .= '<tr>';

                $output .= '<td><span>' . wc_stock_amount( $pricing_rule_sets['rules'][ $key ]['from'] ) . $rules_to . '</span></td>';

                switch ( $pricing_rule_sets['rules'][ $key ]['type'] ) {

                        case 'price_discount':
                                $output .= '<td><span>' . sprintf( __( '%1$s ', 'wc-pricing-table' ), wc_price( $pricing_rule_sets['rules'][ $key ]['amount'] ) ) . '</span></td>';
                                break;
                        case 'fixed_price':
                                $output .= '<td><span>' . sprintf( __( '%1$s ', 'wc-pricing-table' ), wc_price( $pricing_rule_sets['rules'][ $key ]['amount'] ) ) . '</span></td>';
                                break;
                        case 'percentage_discount':
                                global $product;
                                $percentage_amount    = (float) $pricing_rule_sets['rules'][ $key ]['amount'];
                                $discount_in_hundreds = ( 100 - (float) $pricing_rule_sets['rules'][ $key ]['amount'] ) / 100; // example: 0.97
                                $discounted_price     = $product->get_price() * $discount_in_hundreds;
                                $output .= '<td><span>' . sprintf( __( '%1$s ', 'wc-pricing-table' ), wc_price( $discounted_price ) ) . '</span></td>';
                                break;
                }

                $output .= '</tr>';

        }
}

$output .= '</table>';

echo $output;

And 1 method in
class-wc-pricing-table-display.php

public function codup_wc_pricing_table_bulk_pricing_table_output($pricing_rule_sets) {
                
                $is_any_price_discount_item = current(array_filter($pricing_rule_sets['rules'], function($item) {
                        return isset($item['type']) && ($item['type'] == 'price_discount' || $item['type'] == 'fixed_price' ||
                                $item['type'] == 'percentage_discount');
                }));

Attachments (3)

wc-pricing-table-template.php (1.9 KB) - added by wpsilver 6 years ago.
wc-pricing-table-template.2.php (1.9 KB) - added by wpsilver 6 years ago.
class-wc-pricing-table-display.php (6.7 KB) - added by wpsilver 6 years ago.

Download all attachments as: .zip

Change History (3)

Note: See TracTickets for help on using tickets.