Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created December 9, 2025 11:07
Show Gist options
  • Select an option

  • Save webtoffee-git/cf4d5161127e8b5778c636c897d961ab to your computer and use it in GitHub Desktop.

Select an option

Save webtoffee-git/cf4d5161127e8b5778c636c897d961ab to your computer and use it in GitHub Desktop.
Custom code snippet to include subtotal, Shipping amount, Cart discount, Order discount, Fee, Order total and payment method in the QR code - By WebToffee
<?php //Do not copy this line of code
add_filter("wf_pklist_alter_find_replace_in_qrcode", "add_order_details_to_qrcode_currency_code", 10, 6);
function add_order_details_to_qrcode_currency_code($find_replace_in_qrcode, $template_type, $order, $box_packing, $order_package, $custom_qr_details) {
if (!is_a($order, 'WC_Order')) {
return $find_replace_in_qrcode;
}
$currency_code = $order->get_currency();
// Helper function to format amount with currency code (plain text)
function format_amount_with_currency_code($amount, $currency_code) {
return wc_format_decimal($amount, 2) . ' ' . $currency_code;
}
// Subtotal
$find_replace_in_qrcode['[invoice_qrcode_subtotal]'] = format_amount_with_currency_code($order->get_subtotal(), $currency_code);
// Shipping: show amount first, then name in brackets
$shipping_items = $order->get_items('shipping');
$shipping_details = [];
foreach ($shipping_items as $shipping_item) {
$shipping_method = $shipping_item->get_name();
$shipping_total = format_amount_with_currency_code($shipping_item->get_total(), $currency_code);
$shipping_details[] = $shipping_total . ' (' . $shipping_method . ')';
}
$find_replace_in_qrcode['[invoice_qrcode_shipping_details]'] = !empty($shipping_details) ? implode(', ', $shipping_details) : 'N/A';
// Cart discount
$find_replace_in_qrcode['[invoice_qrcode_cart_discount]'] = format_amount_with_currency_code($order->get_discount_total(), $currency_code);
// Order discount (same as cart discount)
$find_replace_in_qrcode['[invoice_qrcode_order_discount]'] = format_amount_with_currency_code($order->get_discount_total(), $currency_code);
// Fees: show amount first, then name in brackets
$fees = $order->get_fees();
$fee_details = [];
foreach ($fees as $fee) {
$fee_total = format_amount_with_currency_code($fee->get_total(), $currency_code);
$fee_name = $fee->get_name();
$fee_details[] = $fee_total . ' (' . $fee_name . ')';
}
$find_replace_in_qrcode['[invoice_qrcode_fees]'] = !empty($fee_details) ? implode(', ', $fee_details) : 'N/A';
// Order total
$find_replace_in_qrcode['[invoice_qrcode_order_total]'] = format_amount_with_currency_code($order->get_total(), $currency_code);
// Payment method
$payment_method = $order->get_payment_method_title();
$find_replace_in_qrcode['[invoice_qrcode_payment_method]'] = $payment_method ? $payment_method : 'N/A';
return $find_replace_in_qrcode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment