Skip to content

Plugin filters

Denis Žoljom edited this page Aug 30, 2023 · 1 revision

List of available filters in the plugin

Overwrite the checkout request for specific payment cases

This filter is used if you have globally selected the API request to happen on manual status change of the order, but you want to allow some payment gateways to execute on the checkout.

Usage:

add_filter('woo_solo_api_overwrite_request_on_checkout', 'my_payment_processor_overwrite', 10, 2);

function my_payment_processor_overwrite($sendControl, $order) {
  // Say we want to allow api call on checkout for direct bank transfer (bacs),
  // and all others on status change.

  // Check the payment gateway from the order.
  $paymentMethod = $order->get_payment_method();

  // Check if the current payment method is the one you want to overwrite.
  if ($paymentMethod === 'bacs') {
    return 'checkout';
  }

  // Default fallback.
  return $sendControl;
}
@param string $sendControl Type of send control. Can be 'checkout' or 'status_change'.
@param WC_Order $order Order object.

Filters the custom message for customer note

If you need to extend the customer note, you can just hook to this filter and modify the existing content

Usage:

add_filter('woo_solo_api_modify_customer_note', 'my_customer_filter', 10, 2);

function my_customer_filter($customerNote, $order) {
  // (maybe) modify $customerNote.
  return $customerNote;
}
@param string $customerNote Existing customer note.
@param WC_Order $order Order object

Filters the Solo API request body before it's being prepared for sending

If you need to modify the request towards the SOLO API, you can just hook to this filter and modify the request body.

Usage:

add_filter('woo_solo_api_modify_request_body', 'my_customer_filter', 10, 2);

function my_customer_filter($requestBody, $order) {
  // (maybe) modify $requestBody.
  return $requestBody;
}
@param array $requestBody Existing customer note.

Modify the email message from the options

Email message can be set in the options and will be outputted here. If, for whatever reason we want to modify it some more, we can do that here.

Usage:

add_filter('woo_solo_api_modify_options_email_message', 'my_message_filter', 10, 3);

function my_message_filter($emailMessage, $orderId, $email) {
  // (maybe) modify $emailMessage.
  return $emailMessage;
}
@param string $emailMessage Email message from options to filter.
@param int    $orderId Order ID.
@param string $email Email address of the person for whom this message needs to be send to.

Modify the default email message

If you don't set the message in the options, you can still filter the default one.

Usage:

add_filter('woo_solo_api_modify_default_email_message', 'my_message_filter', 10, 3);

function my_message_filter($defaultMessage, $orderId, $email) {
  // (maybe) modify $defaultMessage.
  return $defaultMessage;
}
@param string $defaultMessage Email message to filter.
@param int    $orderId Order ID.
@param string $email Email address of the person for whom this message needs to be send to.

Modify the email title from the options

Email title for the customer can be set in the options, but you can modify it further with this filter.

Usage:

add_filter('woo_solo_api_modify_options_email_title', 'my_title_filter', 10, 2);

function my_title_filter($emailTitle, $orderId) {
  // (maybe) modify $emailTitle.
  return $emailTitle;
}
@param string $emailTitle Email title.
@param int    $orderId Order ID.

Modify the default email title from the options

If you don't use the title from the options, you can use default one. And modify it.

Usage:

add_filter('woo_solo_api_modify_default_email_title', 'my_title_filter', 10, 2);

function my_title_filter($defaultTitle, $orderId) {
  // (maybe) modify $defaultTitle.
  return $defaultTitle;
}
@param string $emailTitle Email title.
@param int    $orderId Order ID.

Filter email headers

When email to customer is sent, maybe you want to add something more. In that case you'll probably need to modify the headers sent with the email. Default ones are

[
	'MIME-Version: 1.0',
	'Content-Type: text/html',
];

You can add to that list.

Usage:

add_filter('woo_solo_api_email_headers', 'my_custom_email_headers', 10);

function my_custom_email_headers($headers) {
  // (maybe) modify $headers.
  return $headers;
}
@param array $headers Email headers to pass to wp_mail.

Filter the 'from' name set from the options

Usage:

add_filter('woo_solo_api_change_email_from_name', 'my_custom_from_name', 10);

function my_custom_from_name($name) {
  // (maybe) modify $name.
  return $name;
}
@param string $name Name to change in the "From" field.

Add a global discount

WooCommerce will handle counting the discounts for us. This is why this is set to 0. We can hook into this if we want to change it. But this hook will affect every item. So use it with care.

Usage:

add_filter('woo_solo_api_add_global_discount', 'my_global_discount', 10, 1);

function my_global_discount($globalDiscount) {
  // (maybe) modify $globalDiscount.
  return $globalDiscount;
}
@param int $globalDiscount The value of the global discount to apply to every item.

Modify tax rates

This hook is used to set different tax rates for items based on certain criteria. For instance, if you want to modify taxes based on location you can change it here (if for some reason it's not working from the default settings).

Usage:

add_filter('woo_solo_api_modify_tax_rate', 'my_tax_rate', 10, 3);

function my_tax_rate($taxRate, $itemData, $taxRates) {
  // (maybe) modify $taxRate.
  return $taxRate;
}
@param float $taxRate  The value of the tax rate for the current order item.
@param array $itemData The data for the current order item.
@param array $taxRates The value of the tax rates for the current order item.

Modify the bill type

Use this filter if you need to dynamically change the bill type.

Usage:

add_filter('woo_solo_api_modify_bill_type', 'my_customer_filter', 10, 3);

function my_customer_filter($billType, $paymentMethod, $order) {
  // (maybe) modify $billType, based on some external parameters or $paymentMethod or $order.
  return $billType;
}
@param string $billType Existing bill type.
@param string $paymentMethod Selected payment method for the current order.
@param object|WC_Order $order Current order.

Filter the unit measure for the current item

Use this filter if you need to dynamically change measure for the item. Unit measure MUST be an integer in the list of measures (check the API documentation for details).

add_filter('woo_solo_api_modify_item_measure', 'my_customer_filter', 10, 4);

function my_customer_filter($measure, $itemNo, $order, $itemData) {
  // Modify multiple item numbers in your order based on some settings, meta value, etc.
  switch ($itemNo) {
    case 0:
      $measure = 7;
      break;
    case 1:
      $measure = 19;
      break;
    default:
      $measure = 2;
      break;
  }

  // Or filter based on $order object or $itemData which contains other information about the product.

  return $measure;
}
@param int $measure Current unit measure.
@param int $itemNo Current item in the list.
@param object|WC_Order $order Current order.
@param array $itemData Current item data.

Filter the unit measure for the current shipping item

Use this filter if you need to dynamically change measure for the shipping item. Unit measure MUST be an integer corresponding to the list of measures.

Be careful when changing the measure using the above filter, as the shipping item should probably be a piece (2).

add_filter('woo_solo_api_modify_shipping_item_measure', 'my_customer_filter', 10, 4);

function my_customer_filter($measure, $itemNo, $order, $itemData) {
    return 2; // Corresponds to: piece.
}
@param int $measure Current shipping unit measure. Will be picked up by whatever is in the default measure.
@param int $itemNo Current item in the list.
@param object|WC_Order $order Current order.
@param object|null $shippingObject Current shipping item data.