admin paneli siparislerim sayfası ödeme yöntemine göre arka planı renklendiriyor, ayrıca siparişlerim sayfasına sipariş verilen ürün ve varyasyon bilgisi, müşteri sipariş notu sütunlarını ekliyor.
function custom_add_payment_method_column($columns) {
$columns['payment_method'] = __('Payment Method', 'my-custom-theme');
$columns['ordered_items'] = __('Ordered Items', 'my-custom-theme');
$columns['customer_notes'] = __('Customer Notes', 'my-custom-theme');
return $columns;
}
function custom_display_payment_method_column($column, $post_id) {
$order = wc_get_order($post_id);
switch ($column) {
case 'payment_method':
$payment_method = $order->get_payment_method();
$payment_gateway = WC()->payment_gateways->payment_gateways()[$payment_method];
$payment_method_title = $payment_gateway ? $payment_gateway->get_title() : $payment_method;
// Set background color based on payment method
$background_color = '';
switch ($payment_method) {
case 'cod':
$background_color = 'yellow';
break;
case 'paytrcheckout':
$background_color = 'blue';
break;
case 'bacs':
$background_color = 'red';
break;
}
echo '<div style="background-color: ' . $background_color . ';">' . $payment_method_title . '</div>';
break;
case 'ordered_items':
foreach ($order->get_items() as $item_id => $item) {
$product = $item->get_product();
$product_name = $product ? $product->get_name() : $item->get_name();
$variation_data = $item->get_variation_id() ? wc_get_product($item->get_variation_id())->get_variation_attributes() : array();
echo '<p>' . sprintf('%s - %sx%s', $product_name, $item->get_quantity(), implode(', ', $variation_data)) . '</p>';
}
break;
case 'customer_notes':
echo $order->get_customer_note();
break;
}
}
add_filter('manage_edit-shop_order_columns', 'custom_add_payment_method_column');
add_action('manage_shop_order_posts_custom_column', 'custom_display_payment_method_column', 10, 2);