Skip to content

Commit

Permalink
make sure payment display matches the POS cart (excl tax)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed May 1, 2023
1 parent d8ade91 commit 675f2b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
38 changes: 19 additions & 19 deletions includes/API/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ public function __construct( WP_REST_Request $request ) {
add_filter( 'option_woocommerce_tax_based_on', array( $this, 'tax_based_on' ), 10, 2 );
}


public function incoming_shop_order(): void {
$raw_data = $this->request->get_json_params();

/*
* WC REST validation enforces email address for orders
* this hack allows guest orders to bypass this validation
*/
if ( isset( $raw_data['customer_id'] ) && 0 == $raw_data['customer_id'] ) {
add_filter('is_email', function ( $result, $email ) {
if ( ! $email ) {
return true;
}

return $result;
}, 10, 2);
}
}

/**
* Filters the value of the woocommerce_tax_based_on option.
*
Expand All @@ -72,25 +91,6 @@ public function tax_based_on( $value, $option ) {
return $tax_based_on;
}


public function incoming_shop_order(): void {
$raw_data = $this->request->get_json_params();

/*
* WC REST validation enforces email address for orders
* this hack allows guest orders to bypass this validation
*/
if ( isset( $raw_data['customer_id'] ) && 0 == $raw_data['customer_id'] ) {
add_filter('is_email', function ( $result, $email ) {
if ( ! $email ) {
return true;
}

return $result;
}, 10, 2);
}
}

public function test_email() {
$break = '';

Expand Down
13 changes: 13 additions & 0 deletions includes/Templates/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function __construct( int $order_id ) {
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );

add_action( 'wp_enqueue_scripts', array( $this, 'remove_scripts' ), 100 );

add_filter( 'option_woocommerce_tax_display_cart', array( $this, 'tax_display_cart' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -177,4 +179,15 @@ private function create_customer_nonce() {

return substr( wp_hash( $i . '|woocommerce-pay|' . $uid . '|' . $token, 'nonce' ), - 12, 10 );
}

/**
* Filters the value of the woocommerce_tax_display_cart option.
* The POS is always exclusive of tax, so we show the same for the payments page to avoid confusion.
*
* @param mixed $value Value of the option.
* @param string $option Option name.
*/
public function tax_display_cart( $value, $option ): string {
return 'excl';
}
}

0 comments on commit 675f2b8

Please sign in to comment.