Publicar empesa
Title | Filled? | Date Posted | Listing Expires | Actions |
---|---|---|---|---|
Multiuso Produto de Limpeza e Descartáveis | – | 15/07/2024 | 15/08/2025 |
function bellanetfiber_gerar_cupom_texto($order, $site_info) { $output = ''; // Logo (texto simples) $output .= "***** OUTLET NAME *****\n\n"; // Informações da loja $output .= "Loja: " . strtoupper($site_info->blogname) . "\n"; $output .= "Phone: +1 987-XXX-321\n\n"; // Dados do pedido $output .= "Nº do pedido: #" . $order->get_id() . "\n"; $output .= "Data: " . $order->get_date_created()->date('d/m/Y, h:i A') . "\n\n"; // Dados do cliente $output .= "Cliente:\n"; $output .= "Name: " . $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() . "\n"; $output .= "ID: " . $order->get_customer_id() . "\n"; $output .= "Telefone: " . $order->get_billing_phone() . "\n"; // Endereço do cliente $address = $order->get_billing_address_1(); if ($order->get_billing_address_2()) { $address .= ', ' . $order->get_billing_address_2(); } $address .= ', ' . $order->get_billing_city() . ', ' . $order->get_billing_state(); $output .= "Address: " . $address . "\n\n"; // Itens do pedido $output .= "SL\tItem\tQtd:\tTotal\n"; $i = 1; foreach ($order->get_items() as $item) { $product_name = $item->get_name(); $qty = $item->get_quantity(); $total = wc_price($item->get_total(), array('currency' => $order->get_currency())); $unit_price = wc_price($item->get_total() / $qty, array('currency' => $order->get_currency())); // Linha com número, nome e valores - alinhamento simples com tabs e espaços // Para impressora térmica, cuidado com espaçamento, aqui um exemplo básico: $output .= $i . "\t" . $product_name . " - R$ " . number_format(floatval(str_replace(['R$', ',', ' '], ['', '.', ''], $unit_price)), 2, ',', '') . " " . $total . "\n"; $output .= "\t\t" . $qty . "\t" . $total . "\n"; $i++; } // Totais gerais $total_order = wc_price($order->get_total(), array('currency' => $order->get_currency())); $subtotal = wc_price($order->get_subtotal(), array('currency' => $order->get_currency())); $tax = wc_price($order->get_total_tax(), array('currency' => $order->get_currency())); $discount = wc_price($order->get_total_discount(), array('currency' => $order->get_currency())); $output .= "Total\t" . $subtotal . "\n"; $output .= "Fiscal\t" . $tax . "\n"; if ($discount && $discount != 'R$0,00') { $output .= "Desconto (" . round(($order->get_total_discount() / $order->get_subtotal()) * 100) . "%)\t-" . $discount . "\n"; } // Aqui taxa extra (se você quiser taxa adicional, tem que puxar de algum meta, vou deixar fixo 10% como exemplo) $taxa_extra_valor = $order->get_meta('_taxa_extra'); // caso tenha meta com taxa extra if ($taxa_extra_valor) { $output .= "Taxa (10%)\t" . wc_price($taxa_extra_valor, array('currency' => $order->get_currency())) . "\n"; } $output .= "Total Do Pedido\t" . $total_order . "\n"; // Pagamento e troco (se for dinheiro) $payment_method = wc_get_payment_gateway_by_order($order); $payment_title = $payment_method ? $payment_method->get_title() : 'N/A'; $output .= "Forma De Pagamento\n"; $output .= $payment_title . "\n"; if ($payment_title === 'Dinheiro') { $valor_pago = $order->get_meta('_valor_pago'); // meta para valor dado (troco) if ($valor_pago) { $troco = floatval($valor_pago) - floatval($order->get_total()); $output .= "Quantidade Dada\tR$ " . number_format(floatval($valor_pago), 2, ',', '') . "\n"; $output .= "Retorno\tR$ " . number_format($troco > 0 ? $troco : 0, 2, ',', '') . "\n"; } } $output .= "--------\n"; $output .= "***** Obrigado pela preferência! *****\n"; return $output; }