To jest Poziom deweloperski dokument. Jeśli nie jesteś zaznajomiony z kodem/szablonami i rozwiązywaniem potencjalnych konfliktów, skontaktuj się z programistą zaznajomionym z FooSales i/lub WooCommerce. Te fragmenty są dostarczane jako uprzejmość i mają służyć jako punkt wyjścia do pomocy w określonych potrzebach dostosowywania. Nie jesteśmy w stanie zapewnić wsparcia dla dostosowań w ramach naszych Warunki świadczenia usług.
Przechwytywanie opłat Square podczas realizacji zamówienia #
Jeśli korzystasz z wtyczki eksportowej innej firmy do eksportowania zamówień i przetwarzasz płatności za pomocą Square, możesz chcieć uwzględnić opłaty, które Square odlicza od płatności w eksporcie sprzedaży. Ten dokument pomocy zawierał wcześniej fragment kodu, który przechwytywał opłaty za przetwarzanie Square jako metadane po zakończeniu zamówienia. Nie obsługiwało to jednak płatności podzielonych, a ponieważ struktura wtyczki 1.40.0+ została całkowicie zmieniona, fragment kodu nie będzie już działał. Funkcjonalność zawarta we fragmencie kodu została dodana do podstawowej funkcjonalności wtyczki, która obsługuje również płatności podzielone i różne statusy przesyłania zamówień w wersji wtyczki 1.40.2.
Uwaga że jeśli wcześniej dodałeś fragment kodu do pliku functions.php, to musi go usunąć aby zapobiec krytycznym błędom podczas składania zamówień za pośrednictwem FooSales.
Więcej informacji na temat sposobu rejestrowania opłat Square można znaleźć w naszej witrynie Dokument pomocy integracji płatności Square.
Dodaj notatkę zamówienia z FooSales do wiadomości e-mail administratora WooCommerce. #
Dodaj następujący fragment kodu do motywu functions.php jeśli chcesz, aby "Notatka o zamówieniu" dodana do zamówienia w FooSales była wyświetlana w wiadomościach e-mail administratora WooCommerce.
add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email', 10, 4 );
function woo_add_order_notes_to_email($order, $sent_to_admin, $plain_text, $email) {
if ( isset($post->ID) )
$id = $post->ID;
else
$id = $order->ID;
if ($sent_to_admin && 'foosales_app' == get_post_meta($id, '_foosales_order_source', true)) {
$args = array(
'order_id' => $id,
'type' => ''
);
$notes = wc_get_order_notes( $args );
echo '<h2>' . __( 'Uwagi do zamówienia', 'woocommerce' ) . '</h2>';
echo '<ul class="order_notes">';
if ( $notes ) {
?>
<li>
<div class="note_content">
content ) ) ); ?>
</div>
</li>
<?php } else { echo '<li>' . __( 'Nie ma jeszcze notatek dla tego zamówienia.', 'woocommerce' ) . '</li>';
}
echo '</ul>';
}
}
Wyślij szczegóły zamówienia z FooSales i wypełnioną wiadomość e-mail ze strony internetowej #
Dodaj następujący fragment kodu do motywu functions.php plik, jeśli chcesz automatycznie wysyłać wiadomość e-mail ze szczegółami zamówienia, gdy zamówienie zostanie złożone za pośrednictwem FooSales, i wysłać wiadomość e-mail z zakończonym zamówieniem, gdy zamówienie zostanie złożone za pośrednictwem interfejsu użytkownika witryny.
add_filter( 'woocommerce_email_enabled_customer_completed_order', 'is_foosales', 9999, 2 );
function is_foosales($enabled, $order ) {
if ( ! empty( $order ) && 'foosales_app' === $order->get_meta( '_foosales_order_source', true ) ) {
return false;
}
return $enabled;
}
add_action( 'woocommerce_order_status_completed', 'send_invoice_on_completed' );
function send_invoice_on_completed( $order_id ) {
$wc_order = wc_get_order($order_id);
if ( ! empty( $wc_order ) && 'foosales_app' === $wc_order->get_meta( '_foosales_order_source', true ) ) {
$emails = WC()->mailer()->get_emails();
$emails['WC_Email_Customer_Invoice']->trigger( $order_id );
}
}
Implement partial use for coupon codes #
Dodaj następujący fragment kodu do motywu functions.php file if you want to enable the partial use of coupon codes. This means that if the coupon code amount is more than the total price of the items being purchased, then the amount owed would be 0 and the total price will be deducted from the coupon code amount so that there is credit left to be used in the future.
// 1. Process coupon adjustments on active order completion/processing
add_action( 'woocommerce_order_status_processing', 'adjust_partially_used_coupon_amount', 10, 1 );
add_action( 'woocommerce_order_status_completed', 'adjust_partially_used_coupon_amount', 10, 1 );
function adjust_partially_used_coupon_amount( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
// Prevent code from running multiple times on the same order
if ( $order->get_meta( '_coupon_amount_adjusted' ) ) {
return;
}
$coupons = $order->get_coupons();
foreach ( $coupons as $item ) {
$code = $item->get_code();
$coupon = new WC_Coupon( $code );
// Only target fixed cart discount coupons
if ( $coupon->get_id() && $coupon->is_type( 'fixed_cart' ) ) {
$coupon_original_amount = (float) $coupon->get_amount();
$discount_used = (float) $item->get_discount();
if ( $coupon_original_amount > $discount_used ) {
// PARTIAL USE: Reduce balance and restore 1 usage count so it stays active
$remaining_balance = $coupon_original_amount - $discount_used;
$coupon->set_amount( $remaining_balance );
$usage_count = $coupon->get_usage_count();
if ( $usage_count > 0 ) {
$coupon->set_usage_count( $usage_count - 1 );
}
$coupon->save();
} elseif ( $coupon_original_amount > 0 && abs( $coupon_original_amount - $discount_used ) < 0.001 ) {
// FINAL USE: Full remaining balance spent. Set balance to 0.
// Leave usage_count alone so WooCommerce natural limits apply.
$coupon->set_amount( 0 );
$coupon->save();
}
}
}
// Mark order as processed so status changes don't re-trigger this logic
$order->update_meta_data( '_coupon_amount_adjusted', 'yes' );
$order->save();
}
// 2. Restore coupon balance if order is cancelled, refunded, or failed
add_action( 'woocommerce_order_status_cancelled', 'restore_partially_used_coupon_amount', 10, 1 );
add_action( 'woocommerce_order_status_refunded', 'restore_partially_used_coupon_amount', 10, 1 );
add_action( 'woocommerce_order_status_failed', 'restore_partially_used_coupon_amount', 10, 1 );
function restore_partially_used_coupon_amount( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
return;
}
// Only attempt restoration if the coupon was previously deducted on this order
if ( ! $order->get_meta( '_coupon_amount_adjusted' ) ) {
return;
}
// Prevent double-restoration if status changes between cancelled/refunded
if ( $order->get_meta( '_coupon_amount_restored' ) ) {
return;
}
$coupons = $order->get_coupons();
foreach ( $coupons as $item ) {
$code = $item->get_code();
$coupon = new WC_Coupon( $code );
if ( $coupon->get_id() && $coupon->is_type( 'fixed_cart' ) ) {
$current_balance = (float) $coupon->get_amount();
$discount_applied = (float) $item->get_discount();
if ( $discount_applied > 0 ) {
$restored_balance = $current_balance + $discount_applied;
$coupon->set_amount( $restored_balance );
// If coupon was completely depleted (0) and is now restored, reduce usage count so it reactivates
if ( $current_balance == 0 && $restored_balance > 0 ) {
$usage_count = $coupon->get_usage_count();
if ( $usage_count > 0 ) {
$coupon->set_usage_count( $usage_count - 1 );
}
}
$coupon->save();
}
}
}
// Mark order meta as restored
$order->update_meta_data( '_coupon_amount_restored', 'yes' );
$order->save();
}
Hide WooCommerce Point of Sale Settings #
Dodaj następujący fragment kodu do motywu functions.php file if you want to hide the Point of Sale settings added by WooCommerce as of version 11.
// Remove the built-in WooCommerce Point of Sale settings tab.
add_filter( 'woocommerce_settings_tabs_array', 'remove_wc_pos_settings_tab', 999, 1 );
function remove_wc_pos_settings_tab( $tabs ) {
if ( isset( $tabs['point-of-sale'] ) ) {
unset( $tabs['point-of-sale'] );
}
return $tabs;
}
// Remove the All Sales Channels filter on the Orders page.
add_action( 'admin_head', 'hide_sales_channel_order_filter' );
function hide_sales_channel_order_filter() {
$screen = get_current_screen();
// Target the WooCommerce orders listing screen
if ( isset( $screen->id ) && ( $screen->id === 'woocommerce_page_wc-orders' || $screen->id === 'edit-shop_order' ) ) {
echo '<style>
select[name="_created_via"],
#sales_channel {
display: none !important;
}
</style>';
}
}
