Skip to content

Commit

Permalink
Add get_quantity method
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmoore committed Dec 22, 2023
1 parent 10c7954 commit d3b9a9a
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ public function ajax_add_to_cart() {
return;
}

// Payment Request Button sends the quantity as qty. WooPay sends it as quantity.
if ( isset( $_POST['quantity'] ) ) {
$quantity = absint( $_POST['quantity'] );
} elseif ( isset( $_POST['qty'] ) ) {
$quantity = absint( $_POST['qty'] );
} else {
$quantity = 1;
}
$quantity = $this->get_quantity();

$product_type = $product->get_type();

Expand Down Expand Up @@ -223,4 +216,20 @@ public function get_total_label() {
$statement_descriptor = $this->account->get_statement_descriptor();
return str_replace( "'", '', $statement_descriptor ) . apply_filters( 'wcpay_payment_request_total_label_suffix', ' (via WooCommerce)' );
}

/**
* Gets quantity from request.
*
* @return int
*/
private function get_quantity() {
// Payment Request Button sends the quantity as qty. WooPay sends it as quantity.
if ( isset( $_POST['quantity'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
return absint( $_POST['quantity'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
} elseif ( isset( $_POST['qty'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
return absint( $_POST['qty'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
} else {
return 1;
}
}
}

0 comments on commit d3b9a9a

Please sign in to comment.