Skip to content

Commit b102ac7

Browse files
fix: fees format on cart and checkout (#558)
Added the fees to WooCommerce's `fees_api` to remove the prefix number from the label and generate the unique ID for fees.
1 parent 5639e36 commit b102ac7

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

inc/prices.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,10 +1302,18 @@ function ppom_price_cart_fee( $cart ) {
13021302
} else {
13031303
$matrix_discount = $matrix_found['raw_price'];
13041304
}
1305-
$discount_label = $cart_counter . '-' . $matrix_found['label'];
1305+
$discount_label = $matrix_found['label'];
13061306
$matrix_discount = floatval( $matrix_discount );
13071307
$discount_taxable = apply_filters( 'ppom_matrix_discount_taxable', false, $item, $cart );
1308-
$cart->add_fee( esc_html( $discount_label ), - $matrix_discount, $discount_taxable );
1308+
$cart->fees_api()->add_fee(
1309+
array(
1310+
'id' => 'ppom_matrix_fee_' . $cart_counter,
1311+
'name' => esc_html( $discount_label ),
1312+
'amount' => -abs( (float) $matrix_discount ),
1313+
'taxable' => $discount_taxable,
1314+
'tax_class' => '',
1315+
)
1316+
);
13091317
// ppom_pa($discount_label);
13101318
}
13111319

@@ -1320,7 +1328,10 @@ function ppom_price_cart_fee( $cart ) {
13201328
$fee_price = apply_filters( 'ppom_option_price', $fee['price'] );
13211329
$taxable = $fee['taxable']; // deprecated soon
13221330

1323-
$label = "{$fee_no}-{$label} ({$option_label})";
1331+
$label = "{$label}";
1332+
if ( $option_label ) {
1333+
$label .= " ({$option_label})";
1334+
}
13241335
$label = apply_filters( 'ppom_fixed_fee_label', $label, $fee, $item );
13251336

13261337

@@ -1346,7 +1357,15 @@ function ppom_price_cart_fee( $cart ) {
13461357
$fee_price = $fee_price - $total_tax;
13471358
}
13481359

1349-
$cart->add_fee( esc_html( $label ), $fee_price, $taxable, $tax_class );
1360+
$cart->fees_api()->add_fee(
1361+
array(
1362+
'id' => 'ppom_fee_' . $fee_no,
1363+
'name' => esc_html( $label ),
1364+
'amount' => (float) $fee_price,
1365+
'taxable' => $taxable,
1366+
'tax_class' => $tax_class,
1367+
)
1368+
);
13501369
++$fee_no;
13511370
}
13521371
}

inc/woocommerce.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ function ppom_woocommerce_add_fixed_fee( $cart ) {
661661
}
662662

663663

664-
$label = $fee_no . '-' . $fee['product_title'] . ': ' . $fee['label'];
664+
$label = $fee['product_title'] . ': ' . $fee['label'];
665665
$label = apply_filters( 'ppom_fixed_fee_label', $label, $fee, $item );
666666

667667
$taxable = ( isset( $fee['taxable'] ) && $fee['taxable'] == 'on' ) ? true : false;
@@ -678,7 +678,14 @@ function ppom_woocommerce_add_fixed_fee( $cart ) {
678678
$fee_price = apply_filters( 'ppom_cart_fixed_fee', $fee_price, $fee, $cart );
679679

680680
if ( $fee_price != 0 ) {
681-
$cart->add_fee( esc_html( $label ), $fee_price, $taxable );
681+
$cart->fees_api()->add_fee(
682+
array(
683+
'id' => 'ppom_fee_' . $fee_no,
684+
'name' => esc_html( $label ),
685+
'amount' => (float) $fee_price,
686+
'taxable' => $taxable,
687+
)
688+
);
682689
++$fee_no;
683690
}
684691
}

phpcs.baseline.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,6 @@
19001900
<violation file="inc/prices.php" sniff="Squiz.Commenting.FunctionComment.WrongStyle" signature="f0786d6264a342c7836dfe5e7f5528c2710d6db8"/>
19011901
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="042f7db7928fcfae255bf4413fb2a1104200752a"/>
19021902
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="09dad0e8ede31b9e11beb2c13ac0d4a3044cc267"/>
1903-
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="14ccbe23918de1f8b98f3b684627888fcc3a52cf"/>
19041903
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="15ba115c89f6c7c72899a7a66018622a9c95d207"/>
19051904
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="161ccf0b0509b6a6a447228c69c078f252a02376"/>
19061905
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="195854e6f0943a627641867cadba964b03628975"/>
@@ -1925,6 +1924,7 @@
19251924
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="572791ee9fe73fde49700f94eba358b3b09156bc"/>
19261925
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="5b097b12a28c18c51d7a934165c003a313b7cbcd"/>
19271926
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="5cd6288181df9a763e0010f3f3128abceba7b7d5"/>
1927+
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="5f50b12cdda62cc5dd5206376876ceb4ce58e17b"/>
19281928
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="62e20b3a5c452e7cb0b3dbdde8a388c6c6351325"/>
19291929
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="63b6025c084b997e9933bf003db05fef78f2d219"/>
19301930
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="64c75fd9df1bf1d1fcd787f3c537ceec7bc13d19"/>
@@ -1981,7 +1981,6 @@
19811981
<violation file="inc/prices.php" sniff="Squiz.Commenting.InlineComment.InvalidEndChar" signature="ff5432f8b4e66f4c3f51f7719d4d912089796f98"/>
19821982
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="066af45f2e3821c70a86395fd7fe64325c88f2cc"/>
19831983
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="0b376d2ce62a602dc380a2e88b8e1e2e0de916f1"/>
1984-
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="14ccbe23918de1f8b98f3b684627888fcc3a52cf"/>
19851984
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="15ba115c89f6c7c72899a7a66018622a9c95d207"/>
19861985
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="15cd1eb66fa66d8db9440368da2495f245dc8fd1"/>
19871986
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="161ccf0b0509b6a6a447228c69c078f252a02376"/>
@@ -1999,6 +1998,7 @@
19991998
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="53656dfc2b445f0413e894d84db452e8185146e9"/>
20001999
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="572791ee9fe73fde49700f94eba358b3b09156bc"/>
20012000
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="5cd6288181df9a763e0010f3f3128abceba7b7d5"/>
2001+
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="5f50b12cdda62cc5dd5206376876ceb4ce58e17b"/>
20022002
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="65cefa45f39336d48e686f6492e038270f41410c"/>
20032003
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="6c5aa55d98c31910d861c8f378e52d75c5485166"/>
20042004
<violation file="inc/prices.php" sniff="Squiz.PHP.CommentedOutCode.Found" signature="6d6c27929ce754e8227af9fc79496e1d699dabbc"/>

0 commit comments

Comments
 (0)