Skip to content

Commit c0e4d39

Browse files
fix: make compatible with multi-currency plugins (#522)
Added filter `ppom_option_price` to convert the currency value.
1 parent ae8ce17 commit c0e4d39

29 files changed

Lines changed: 101 additions & 77 deletions

classes/inputs/input.measure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function change_option_label( $label, $option, $meta, $product ) {
3636
}
3737

3838
$price = isset( $option['price'] ) ? $option['price'] : 0;
39+
$price = apply_filters( 'ppom_option_price', $price );
3940
$price = wc_price( $price );
4041
$label = $price . '/' . $option['option'];
4142

classes/plugin.class.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ public function __construct() {
354354
add_filter( 'woocommerce_order_again_cart_item_data', 'ppom_wc_order_again_compatibility', 10, 3 );
355355
// Show description tooltip.
356356
add_filter( 'ppom_field_description', array( $this, 'show_tooltip' ), 15, 2 );
357+
358+
add_filter( 'ppom_option_price', array( $this, 'ppom_convert_price' ), 99, 1 );
357359
}
358360

359361
/*
@@ -1094,4 +1096,40 @@ public function is_license_of_type( $type ) {
10941096

10951097
return false;
10961098
}
1099+
1100+
/**
1101+
* Convert price using active multi-currency plugin's filter or function.
1102+
*
1103+
* @param float|int|string|null $price The price to convert.
1104+
* @return float|int|string|null The converted price.
1105+
*/
1106+
public function ppom_convert_price( $price ) {
1107+
if ( '' === $price || null === $price ) {
1108+
return $price;
1109+
}
1110+
if ( is_string( $price ) && false !== strpos( $price, '%' ) ) {
1111+
return $price;
1112+
}
1113+
if ( ! is_numeric( $price ) ) {
1114+
return $price;
1115+
}
1116+
$numeric_price = (float) $price;
1117+
1118+
// WCML.
1119+
if ( has_filter( 'wcml_raw_price_amount' ) ) {
1120+
return apply_filters( 'wcml_raw_price_amount', $numeric_price );
1121+
}
1122+
1123+
// FOX - Currency Switcher.
1124+
if ( has_filter( 'woocs_exchange_value' ) ) {
1125+
return apply_filters( 'woocs_exchange_value', $numeric_price );
1126+
}
1127+
1128+
// CURCY - WooCommerce Multi Currency.
1129+
if ( function_exists( 'wmc_get_price' ) ) {
1130+
return wmc_get_price( $numeric_price );
1131+
}
1132+
1133+
return $price;
1134+
}
10971135
}

inc/admin.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -913,36 +913,36 @@ function ppom_admin_bar_menu() {
913913
function ppom_add_black_friday_data( $configs ) {
914914
$config = $configs['default'];
915915

916-
$message = __( 'Conditional fields, file uploads, pricing formulas. Let customers configure products the way they need. Exclusively for existing PPOM users.', 'woocommerce-product-addon' );
916+
$message = __( 'Conditional fields, file uploads, pricing formulas. Let customers configure products the way they need. Exclusively for existing PPOM users.', 'woocommerce-product-addon' );
917917
$cta_label = __( 'Get PPOM Pro', 'woocommerce-product-addon' );
918918

919-
$plan = apply_filters( 'product_ppom_license_plan', 0 );
920-
$license = apply_filters( 'product_ppom_license_key', false );
921-
$status = apply_filters( 'product_ppom_license_status', false );
919+
$plan = apply_filters( 'product_ppom_license_plan', 0 );
920+
$license = apply_filters( 'product_ppom_license_key', false );
921+
$status = apply_filters( 'product_ppom_license_status', false );
922922
$pro_product_slug = defined( 'PPOM_PRO_BASENAME' ) ? PPOM_PRO_BASENAME : '';
923923

924-
$is_pro = 'valid' === $status;
924+
$is_pro = 'valid' === $status;
925925
$is_expired = 'expired' === $status || 'active-expired' === $status;
926926

927927
if ( $is_pro ) {
928928
// translators: %s is the discount percentage.
929929
$config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - up to %s off', 'woocommerce-product-addon' ), '30%' );
930930
// translators: %1$s - discount, %2$s - discount.
931-
$message = sprintf( __( 'Upgrade your PPOM Pro plan: %1$s off this week. Already on the plan you need? Renew early and save up to %2$s.', 'woocommerce-product-addon' ), '30%', '20%' );
931+
$message = sprintf( __( 'Upgrade your PPOM Pro plan: %1$s off this week. Already on the plan you need? Renew early and save up to %2$s.', 'woocommerce-product-addon' ), '30%', '20%' );
932932
$cta_label = __( 'See your options', 'woocommerce-product-addon' );
933933
} elseif ( $is_expired ) {
934934
// translators: %s is the discount percentage.
935935
$config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'woocommerce-product-addon' ), '50%' );
936-
$message = __( 'Your PPOM Pro features are still here, just locked. Renew at a reduced rate this week.', 'woocommerce-product-addon' );
937-
$cta_label = __( 'Reactivate now', 'woocommerce-product-addon' );
936+
$message = __( 'Your PPOM Pro features are still here, just locked. Renew at a reduced rate this week.', 'woocommerce-product-addon' );
937+
$cta_label = __( 'Reactivate now', 'woocommerce-product-addon' );
938938
} else {
939939
// translators: %s is the discount percentage.
940940
$config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'woocommerce-product-addon' ), '60%' );
941941
// translators: %s - discount.
942942
$config['title'] = sprintf( __( 'PPOM Pro: %s off this week', 'woocommerce-product-addon' ), '60%' );
943943
}
944944

945-
$url_params = array(
945+
$url_params = array(
946946
'utm_term' => $is_pro ? 'plan-' . $plan : 'free',
947947
'lkey' => ! empty( $license ) ? $license : false,
948948
'expired' => $is_expired ? '1' : false,

inc/nmInput.class.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function Regular( $args, $default_value = '' ) {
139139
$onetime = $this->get_attribute_value( 'onetime', $args );
140140
$taxable = $this->get_attribute_value( 'taxable', $args );
141141
$price = $this->get_attribute_value( 'price', $args );
142+
$price = apply_filters( 'ppom_option_price', $price );
142143
$price_without_tax = '';
143144

144145
// Only title without description for price calculation etc.
@@ -277,8 +278,9 @@ public function Measure( $args, $default_value = '' ) {
277278
// $measure_label = $option['label'].'/'.$
278279
$option_id = $option['option_id'];
279280
$unit = $option['raw'];
281+
$price = apply_filters( 'ppom_option_price', $option['price'] );
280282
$html .= '<input checked name="ppom[unit][' . $id . ']" value="' . esc_attr( $unit ) . '" class="form-check-input ppom-measure-unit" type="radio" id="' . esc_attr( $option_id ) . '" data-apply="measure" ';
281-
$html .= sprintf( 'data-use_units="' . esc_attr( $use_units ) . '" data-price="%s" data-label="%s" data-data_name="%s" data-unit="%s" data-optionid="%s">', $option['price'], esc_attr( $data_label ), $id, $unit, $option_id );
283+
$html .= sprintf( 'data-use_units="' . esc_attr( $use_units ) . '" data-price="%s" data-label="%s" data-data_name="%s" data-unit="%s" data-optionid="%s">', $price, esc_attr( $data_label ), $id, $unit, $option_id );
282284
$html .= '<label class="form-check-label" id="' . esc_attr( $option_id ) . '">';
283285
$html .= $option['label'];
284286
$html .= '</label>';
@@ -481,7 +483,7 @@ public function Select( $args, $selected_value = '' ) {
481483
// ppom_pa($value);
482484

483485
$option_label = $value['label'];
484-
$option_price = $value['price'];
486+
$option_price = apply_filters( 'ppom_option_price', $value['price'] );
485487
$option_id = isset( $value['id'] ) ? $value['id'] : '';
486488
$raw_label = $value['raw'];
487489
$without_tax = $value['without_tax'];
@@ -660,7 +662,7 @@ public function Checkbox( $args, $checked_value = array() ) {
660662
foreach ( $options as $key => $value ) {
661663

662664
$option_label = $value['label'];
663-
$option_price = $value['price'];
665+
$option_price = apply_filters( 'ppom_option_price', $value['price'] );
664666
$raw_label = $value['raw'];
665667
$without_tax = $value['without_tax'];
666668
$option_id = $value['option_id'];
@@ -743,7 +745,7 @@ public function Radio( $args, $checked_value = '' ) {
743745
foreach ( $options as $key => $value ) {
744746

745747
$option_label = $value['label'];
746-
$option_price = $value['price'];
748+
$option_price = apply_filters( 'ppom_option_price', $value['price'] );
747749
$raw_label = $value['raw'];
748750
$without_tax = $value['without_tax'];
749751
$option_id = $value['option_id'];
@@ -850,7 +852,7 @@ public function Palettes( $args, $default_value = '' ) {
850852

851853
$color_label = $value['label'];
852854
$option_label = $value['label'];
853-
$option_price = $value['price'];
855+
$option_price = apply_filters( 'ppom_option_price', $value['price'] );
854856
$raw_label = $value['raw'];
855857
$without_tax = $value['without_tax'];
856858

@@ -974,6 +976,7 @@ public function Image( $args, $default_value = '' ) {
974976
$image_title = isset( $image['raw'] ) ? stripslashes( $image['raw'] ) : '';
975977
$image_label = isset( $image['label'] ) ? stripslashes( $image['label'] ) : '';
976978
$image_price = isset( $image['price'] ) ? $image['price'] : 0;
979+
$image_price = apply_filters( 'ppom_option_price', $image_price );
977980
$option_id = $id . '-' . $image_id;
978981

979982
// If price set in %
@@ -1069,6 +1072,7 @@ public function Image( $args, $default_value = '' ) {
10691072
$image_title = isset( $image['raw'] ) ? stripslashes( $image['raw'] ) : '';
10701073
$image_label = isset( $image['label'] ) ? stripslashes( $image['label'] ) : '';
10711074
$image_price = isset( $image['price'] ) ? $image['price'] : 0;
1075+
$image_price = apply_filters( 'ppom_option_price', $image_price );
10721076
$option_id = $id . '-' . $image_id;
10731077

10741078
// If price set in %
@@ -1183,6 +1187,7 @@ public function Pricematrix( $args, $default_value = '' ) {
11831187
if ( ! $is_hidden ) {
11841188
foreach ( $ranges as $opt ) {
11851189
$price = isset( $opt['raw_price'] ) ? trim( $opt['raw_price'] ) : 0;
1190+
$price = apply_filters( 'ppom_option_price', $price );
11861191
$label = isset( $opt['label'] ) ? $opt['label'] : $opt['raw'];
11871192

11881193
if ( ! empty( $opt['percent'] ) ) {
@@ -1357,6 +1362,7 @@ public function Audio_video( $args, $default_value = '' ) {
13571362
$audio_id = isset( $audio['id'] ) ? $audio['id'] : 0;
13581363
$audio_title = isset( $audio['title'] ) ? stripslashes( $audio['title'] ) : 0;
13591364
$audio_price = isset( $audio['price'] ) ? $audio['price'] : 0;
1365+
$audio_price = apply_filters( 'ppom_option_price', $audio_price );
13601366

13611367
// Actually image URL is link
13621368
$audio_url = wp_get_attachment_url( $audio_id );
@@ -1565,6 +1571,7 @@ public function Cropper( $args, $selected_value = '' ) {
15651571

15661572
$option_label = $size['label'];
15671573
$option_price = $size['price'];
1574+
$option_price = apply_filters( 'ppom_option_price', $option_price );
15681575
$raw_label = $size['raw'];
15691576
$without_tax = $size['without_tax'];
15701577
$option_id = $size['option_id'];

inc/prices.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ function ppom_generate_field_price( $field_price, $field_meta, $apply, $option =
821821
$taxable = ( isset( $field_meta['onetime_taxable'] ) && $field_meta['onetime_taxable'] == 'on' ) ? true : false;
822822
$option_label = isset( $option['raw'] ) ? $option['raw'] : '';
823823
$without_tax = isset( $option['without_tax'] ) ? $option['without_tax'] : '';
824+
$field_price = apply_filters( 'ppom_option_price', $field_price );
824825

825826
$label_price = "{$field_title} - " . wc_price( $field_price );
826827
// For bulkquantity

inc/woocommerce.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ function ppom_woocommerce_mini_cart_fixed_fee() {
701701

702702
$item_fee = $fee->total + $fee->tax;
703703
}
704-
// var_dump($fee);
704+
$item_fee = apply_filters( 'ppom_option_price', $item_fee );
705705
$fixed_fee_html .= '<tr>';
706706
$fixed_fee_html .= '<td class="subtotal-text">' . esc_html( $fee->name );
707707
'</td>';
@@ -736,6 +736,8 @@ function ppom_woocommerce_add_item_meta( $item_meta, $cart_item ) {
736736
$meta_name = isset( $meta['name'] ) ? $meta['name'] : '';
737737
$meta_value = isset( $meta['value'] ) ? $meta['value'] : '';
738738
$display = isset( $meta['display'] ) ? $meta['display'] : $meta_value;
739+
$meta_price = isset( $meta['price'] ) ? $meta['price'] : 0;
740+
$meta_price = apply_filters( 'ppom_option_price', $meta_price );
739741
if ( $key == 'ppom_has_quantities' ) {
740742
$hidden = true;
741743
}
@@ -757,8 +759,8 @@ function ppom_woocommerce_add_item_meta( $item_meta, $cart_item ) {
757759
$meta_value = wp_json_encode( $meta_value );
758760
}
759761

760-
if ( apply_filters( 'ppom_show_option_price_cart', false ) && isset( $meta['price'] ) ) {
761-
$meta_value .= ' (' . wc_price( $meta['price'] ) . ')';
762+
if ( apply_filters( 'ppom_show_option_price_cart', false ) && ! empty( $meta_price ) ) {
763+
$meta_value .= ' (' . wc_price( $meta_price ) . ')';
762764
}
763765

764766
$meta_key = stripslashes( $meta_name );
@@ -839,8 +841,8 @@ function ppom_woocommerce_alter_price( $price, $product ) {
839841

840842
$least_price = floatval( $product->get_price() ) - $least_price;
841843
$least_price = wc_format_decimal( $least_price, wc_get_price_decimals() );
842-
// var_dump($least_price);
843-
$price = wc_price( $least_price ) . '-' . $price;
844+
$least_price = apply_filters( 'ppom_option_price', $least_price );
845+
$price = wc_price( $least_price ) . '-' . $price;
844846
} else {
845847

846848
foreach ( $ranges as $range ) {

0 commit comments

Comments
 (0)