Skip to content

Commit

Permalink
add woocommerce_pos_is_pos_order helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Apr 29, 2024
1 parent 65c3131 commit 4a0df87
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 37 deletions.
6 changes: 4 additions & 2 deletions includes/API/Orders_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function wcpos_send_email( WP_REST_Request $request ) {
}

do_action( 'woocommerce_before_resend_order_emails', $order, 'customer_invoice' );
add_filter( 'woocommerce_email_recipient_customer_invoice', array( $this, 'wcpos_recipient_email_address' ), 10, 3 );
add_filter( 'woocommerce_email_recipient_customer_invoice', array( $this, 'wcpos_recipient_email_address' ), 99 );

// Send the customer invoice email.
WC()->payment_gateways();
Expand Down Expand Up @@ -371,13 +371,15 @@ public function wcpos_send_email_permissions_check() {
}

/**
* Get the recipient email address, for manual sending of order emails.
*
* @param string $recipient.
* @param WC_Abstract_Order $order.
* @param WC_Email_Customer_Invoice $WC_Email_Customer_Invoice.
*
* @return string
*/
public function wcpos_recipient_email_address( string $recipient, WC_Abstract_Order $order, WC_Email_Customer_Invoice $WC_Email_Customer_Invoice ) {
public function wcpos_recipient_email_address() {
return $this->wcpos_request['email'];
}

Expand Down
31 changes: 18 additions & 13 deletions includes/Admin/Orders/HPOS_List_Orders.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php
/**
*
*/

namespace WCPOS\WooCommercePOS\Admin\Orders;

use WC_Abstract_Order;

/**
* Class HPOS_List_Orders
*/
class HPOS_List_Orders extends List_Orders {
/**
* NOTE: When HPOS is anabled we go to a different Order List page
Expand All @@ -30,28 +36,27 @@ public function __construct() {
}

/**
* Display the content for the custom column.
*
* @param string $column_name The name of the column to display.
* @param WC_Abstract_Order $order The order object whose data will be used to render the column.
*
* @return void
*/
public function orders_custom_column_content( string $column_name, $order ): void {
if ( 'wcpos' === $column_name ) {
// Check if the order exists and is not a boolean before accessing properties
if ( $order instanceof WC_Abstract_Order ) {
// Use the getter methods for order meta data
$legacy = $order->get_meta( '_pos', true );
$created_via = $order->get_created_via();

// Check if the order was created via WooCommerce POS
if ( 'woocommerce-pos' === $created_via || '1' === $legacy ) {
// Output a custom icon or text to indicate POS order
echo '<span class="wcpos-icon" title="POS Order"></span>';
}
}
if ( 'wcpos' === $column_name && woocommerce_pos_is_pos_order( $order ) ) {
echo '<span class="wcpos-icon" title="POS Order"></span>';
}
}

/**
* Parse the query to filter orders by POS or online.
*
* @TODO - add legacy support for _pos = 1
*
* @param array $args Query args.
* @return array
*/
public function query_args( $args ) {
$pos_order_filter = $_GET['pos_order'] ?? '';

Expand Down
36 changes: 19 additions & 17 deletions includes/Admin/Orders/List_Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace WCPOS\WooCommercePOS\Admin\Orders;

use WC_Abstract_Order;
use const WCPOS\WooCommercePOS\PLUGIN_URL;
use WP_Query;
use const WCPOS\WooCommercePOS\PLUGIN_URL;

class List_Orders {

/**
* List_Orders constructor.
*/
public function __construct() {
// add filter dropdown to orders list page
add_action( 'restrict_manage_posts', array( $this, 'order_filter_dropdown' ) );
Expand All @@ -18,6 +22,11 @@ public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'pos_order_column_width' ) );
}

/**
* Add a filter dropdown to the orders list page.
*
* @return void
*/
public function order_filter_dropdown(): void {
$selected = $_GET['pos_order'] ?? '';

Expand All @@ -37,7 +46,9 @@ public function order_filter_dropdown(): void {
}

/**
* @param WP_Query $query
* Parse the query to filter orders by POS or online.
*
* @param WP_Query $query The WP_Query instance (passed by reference).
*
* @return WP_Query
*/
Expand Down Expand Up @@ -101,6 +112,8 @@ public function parse_query( $query ) {


/**
* Add a custom column to the orders list table.
*
* @param string[] $columns The column header labels keyed by column ID.
*
* @return string[]
Expand All @@ -120,27 +133,16 @@ public function pos_shop_order_column( array $columns ): array {
}

/**
* Display the content for the custom column.
*
* @param string $column_name The name of the column to display.
* @param int $post_id The current post ID.
*
* @return void
*/
public function pos_orders_list_column_content( string $column_name, int $post_id ): void {
if ( 'wcpos' === $column_name ) {
// Use the WC_Abstract_Order object to interact with order data
$order = wc_get_order( $post_id );
// Check if the order exists and is not a boolean before accessing properties
if ( $order instanceof WC_Abstract_Order ) {
// Use the getter methods for order meta data
$legacy = $order->get_meta( '_pos', true );
$created_via = $order->get_created_via();

// Check if the order was created via WooCommerce POS
if ( 'woocommerce-pos' === $created_via || '1' === $legacy ) {
// Output a custom icon or text to indicate POS order
echo '<span class="wcpos-icon" title="POS Order"></span>';
}
}
if ( 'wcpos' === $column_name && woocommerce_pos_is_pos_order( $post_id ) ) {
echo '<span class="wcpos-icon" title="POS Order"></span>';
}
}

Expand Down
10 changes: 6 additions & 4 deletions includes/Admin/Orders/Single_Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ public function wc_order_is_editable( $is_editable, WC_Abstract_Order $order ) {

/**
* Add cashier select to order page.
*
* @param WC_Abstract_Order $order Order object.
*/
public function add_cashier_select( WC_Abstract_Order $order ): void {
// only show if order created by POS
if ( 'woocommerce-pos' !== $order->get_created_via() ) {
public function add_cashier_select( $order ): void {
// only show if order created by POS.
if ( ! woocommerce_pos_is_pos_order( $order ) ) {
return;
}

$cashier_id = $order->get_meta( '_pos_user' );

// Create nonce for security
// Create nonce for security.
wp_nonce_field( 'pos_cashier_select_action', 'pos_cashier_select_nonce' );

echo '<p class="form-field form-field-wide">';
Expand Down
23 changes: 22 additions & 1 deletion includes/wcpos-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

use WCPOS\WooCommercePOS\Admin\Permalink;
use const WCPOS\WooCommercePOS\PLUGIN_PATH;
use WCPOS\WooCommercePOS\Services\Settings;
use const WCPOS\WooCommercePOS\PLUGIN_PATH;
use const WCPOS\WooCommercePOS\SHORT_NAME;
use const WCPOS\WooCommercePOS\VERSION;

Expand Down Expand Up @@ -206,3 +206,24 @@ function woocommerce_pos_faq_url( $page ): string {
return 'http://faq.wcpos.com/v/' . VERSION . '/en/' . $page;
}
}

/**
* Helper function checks whether order is a POS order
*
* @param $order WC_Order|int
* @return bool
*/
if ( ! \function_exists( 'woocommerce_pos_is_pos_order' ) ) {
function woocommerce_pos_is_pos_order( $order ): bool {
$order = is_int( $order ) ? wc_get_order( $order ) : $order;

if ( $order instanceof WC_Order ) {
$legacy = $order->get_meta( '_pos', true );
$created_via = $order->get_created_via();

return 'woocommerce-pos' === $created_via || '1' === $legacy;
}

return false;
}
}
15 changes: 15 additions & 0 deletions templates/pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@
background-color: black;
}
}*/

#splash {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
background-color: #fafbfc;
}

#splash img {
width: 150px;
height: 150px;
}
</style>

<?php do_action( 'woocommerce_pos_head' ); ?>
Expand Down

0 comments on commit 4a0df87

Please sign in to comment.