From 4069e886996b76434d33707b21b15abb443c6a0c Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 20 Oct 2023 11:28:27 +0200 Subject: [PATCH] Add metabox to show payment details --- src/Gateway/GatewayModule.php | 29 +++++++++++++++++++++++++++- src/Gateway/MolliePaymentGateway.php | 6 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index bc5b2a18..1e1a1004 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -6,6 +6,7 @@ namespace Mollie\WooCommerce\Gateway; +use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule; use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait; use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule; @@ -39,6 +40,7 @@ use Mollie\WooCommerce\PaymentMethods\Constants; use Mollie\WooCommerce\Vendor\Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface as Logger; +use WP_Post; class GatewayModule implements ServiceModule, ExecutableModule { @@ -301,10 +303,35 @@ static function ($paymentContext) { $order->save(); } ); - + add_action('add_meta_boxes_woocommerce_page_wc-orders', [$this, 'addShopOrderMetabox'], 10); return true; } + /** + * @param Object $post + * @return void + */ + public function addShopOrderMetabox(object $post) + { + if (! $post instanceof \WC_Order) { + return; + } + $meta = $post->get_meta('_mollie_payment_instructions'); + if (empty($meta)) { + return; + } + $screen = wc_get_container()->get(CustomOrdersTableController::class)->custom_orders_table_usage_is_enabled() + ? wc_get_page_screen_id('shop-order') + : 'shop_order'; + add_meta_box('mollie_order_details', __('Mollie Payment Details', 'mollie-payments-for-woocommerce'), static function () use ($meta) { + $allowedTags = ['strong' => []]; + printf( + '

%s

', + wp_kses($meta, $allowedTags) + ); + }, $screen, 'side', 'high'); + } + /** * Disable Bank Transfer Gateway * diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index f71438a8..6f3b6600 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -836,6 +836,12 @@ public function displayInstructions( if (!empty($instructions)) { $instructions = wptexturize($instructions); + //save instructions in order meta + $order->update_meta_data( + '_mollie_payment_instructions', + $instructions + ); + $order->save(); if ($plain_text) { echo esc_html($instructions) . PHP_EOL;