Skip to content

Instantly share code, notes, and snippets.

@robertmassaioli
Created January 27, 2022 22:09
Show Gist options
  • Save robertmassaioli/765db01077808246fb4e50bcd2656ec6 to your computer and use it in GitHub Desktop.
Save robertmassaioli/765db01077808246fb4e50bcd2656ec6 to your computer and use it in GitHub Desktop.
Invoice For WooCommerce: PO as Required Field
diff --git a/Models/Gateways/IGFW_Invoice_Gateway.php b/Models/Gateways/IGFW_Invoice_Gateway.php
index 1253db2..c047ab7 100644
--- a/Models/Gateways/IGFW_Invoice_Gateway.php
+++ b/Models/Gateways/IGFW_Invoice_Gateway.php
@@ -136,7 +136,7 @@ class IGFW_Invoice_Gateway extends \WC_Payment_Gateway {
if (get_option('igfw_enable_purchase_order_number') == 'yes') {
- echo '<p><b>' . __('Purchase Order (optional)', 'invoice-gateway-for-woocommerce') . '</b></p>';
+ echo '<p><b>' . __('Purchase Order', 'invoice-gateway-for-woocommerce') . '</b></p>';
echo '<p><input type="text" name="igfw_purchase_order_number" placeholder="PO Number"></p>';
echo '<p>' . __('We will generate and send you an invoice for your order, if you have a PO number, please enter it.', 'invoice-gateway-for-woocommerce') . '</p>';
@@ -149,6 +149,17 @@ class IGFW_Invoice_Gateway extends \WC_Payment_Gateway {
}
+ public function validate_fields() {
+ if (get_option('igfw_enable_purchase_order_number') == 'yes') {
+ if (strlen($_POST['igfw_purchase_order_number'] ?: '') == 0) {
+ wc_add_notice('<strong>Purchase Order Number</strong> is a required field.', 'error' );
+ return false;
+ }
+ }
+
+ return true;
+ }
+
/**
* Check If The Gateway Is Available For Use.
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment