Hooks & Filters - pinalj/quotes-for-woocommerce GitHub Wiki

Fetch quote setting status for a product at the front end.

function check_stock_status( $quote_enabled, $product_id ) {
	$_product     = wc_get_product( $product_id );
	$stock_status = $_product->get_stock_status();
	if ( 'instock' !== $stock_status ) {
		$quote_enabled = true;
	}
	return $quote_enabled;
}
add_filter( 'qwc_product_quote_enabled', 'check_stock_status', 10, 2 );

In the above example, if a product is available and in stock, the quote setting status is returned as is. If not (i.e. out of stock or backorders etc.) then quote is enabled for the product.


Display country field in Billing at Checkout when 'Hide Address fields at Checkout' is enabled.

function display_billing_country( $fields ) {
	unset( $fields['billing_country'] );
	return $fields;
}
add_filter( 'qwc_hide_billing_fields_at_checkout', 'display_billing_country', 10, 1 );
add_filter( 'qwc_hide_billing_fields', 'display_billing_country', 10, 1 );

In the above example, we wish to display the country field in the Billing section at Checkout. Hence the field should be unset from the array to ensure it is not hidden.

Fields which can be displayed & their respective keys:

Company name - billing_company

Street Address 1 - billing_address_1

Street Address 2 - billing_address_2

State - billing_state

Town/City - billing_city

PIN/ZIP - billing_postcode

Country/Region - billing_country


Change conflict message displayed on the Cart page when products containing quotes and without quotes are added at the same time.

function change_conflict_message( $message ) {
	$message = __( 'This is a custom message displayed for conflicting products.','quote-wc' );
	return $message;
}
add_filter( 'qwc_cart_conflict_msg', 'change_conflict_message', 10, 1 );

Change page title for Checkout page and Pay for order page.

function change_title( $title, $endpoint, $order_status) {
	if ( 'order-received' === $endpoint ) {
		return $title;
	} else if ( 'order-pay' === $endpoint ) {
		return __( 'Pay for the Order', 'quote-wc' );
	}
	return $title;
}
add_filter( 'qwc_change_checkout_page_title', 'change_title', 10, 3 );

Modify the Payment method name.

function change_method_name ( $name ) {
    return __( 'New Name', 'quote-wc' );
}
add_filter( 'qwc_payment_method_name', 'change_method_name', 10, 1 );

Modify email templates

  1. WordPress Dashboard > WooCommerce > Settings > Emails
  2. Click on the Manage button for the email you wish to modify
  3. Scroll down and click on Copy file to theme button.
  4. This will create a copy of the email in wp-content/themes//quotes-for-wc/emails/
  5. Edit the PHP file as needed.

Modify the quote status for which the Quote Sent email should be sent to the customer.

By default the email is sent for the status 'quote-pending'. In the example below, we are adding the status 'quote-complete'.

function qwc_status_change( $status ) {
	array_push( $status, 'quote-complete' );
	return $status;
}
add_filter( 'qwc_request_sent_allowed_status', 'qwc_status_change', 10, 1 );

Modify the quote status for which the Quote Received email should be sent to the admin.

By default the email is sent for the status 'quote-pending'. In the example below, we are adding the status 'quote-complete'.

function qwc_status_change( $status ) {
	array_push( $status, 'quote-complete' );
	return $status;
}
add_filter( 'qwc_request_new_quote_allowed_status', 'qwc_status_change', 10, 1 );

Modify the list of fields displayed at Checkout when 'Hide Address fields at Checkout' setting is enabled

By default, the first name, last name, email and phone field are displayed when the setting is on. Use the below filters to display/hide additional fields as desired.

e.g. Display the country field.

function display_company( $fields ) {
    unset( $fields['billing_country'] );
    return $fields;
}
add_filter( 'qwc_hide_billing_fields_at_checkout', 'display_company', 10, 1 );
function display_billing( $fields ) {
    unset( $fields['billing_country'] );
    return $fields;
}
add_filter( 'qwc_hide_billing_fields', 'display_billing', 10, 1 );

List of fields available:

'billing_company' - Billing Company
'billing_address_1' - Address field 1
'billing_address_2' - Address field 2
'billing_state' - Billing State
'billing_city' - Billing City
'billing_postcode' - Billing Postcode
'billing_country' - Billing Country

Change default order status assigned to quote orders.

By default the plugin assigns the order status 'Pending Payment' to quote orders when the order is created. Use the below hook to change the same.

function qwc_modify_order_status( $order_id ) {

	if ( $order_id > 0 ) {
		$_order = wc_get_order( $order_id );
		if ( $_order ) {

			// check if order status is pending payment & quote meta is found for the order.
			if ( in_array( $_order->get_status(), array( 'checkout-draft', 'pending' ) ) && 'quote-pending' === $_order->get_meta( '_quote_status' ) ) {
				$_order->update_status( 'wc-quotation' ); // change the order status slug as needed. wc-quotation is an example slug.
				$_order->save();
			}
		}
	}
}
add_action( 'qwc_update_quote_order_status', 'qwc_modify_order_status', 10, 1 );

NOTE: The above code works only for legacy Checkout page and not Checkout Blocks.


Modify price display for quote products

The Quotes plugin hides product prices by default when quotation is enabled for a given product. It also provides a setting 'Enable Price Display' to modify this behaviour. The below hook is used by the Pro version for some features.

function hide_price( $quote_enabled, $product_id ) {
... perform custom checks as needed.... return true if quotes are enabled for the product.
... the plugin will display/hide the price based on the setting...
    $quote_enabled = true;
    return $quote_enabled;
}
add_filter( 'qwc_hide_prices', 'hide_price', 10, 2 );

Display item SKU in emails.

From version 2.8 onwards, the plugin will display the item SKU in emails sent to the admin. The SKU will NOT be displayed for emails sent to customer. This can be modified using the hook below.

Example: Display the item SKU in the request email notification sent to the customer.

function display_sku( $display, $email_id ) {
	if ( 'qwc_request_sent' === $email_id ) {
		$display = true;
	}
	return $display;
}
add_filter( 'qwc_show_sku_email', 'display_sku', 10, 2 );

Email ID & default SKU display status:

  1. Request for New Quote - qwc_req_new_quote - true
  2. New Quote Request Sent - qwc_request_sent - false
  3. Send Quote - qwc_send_quote - false