Filter uncanny-automator

automator_order_summary_html_raw

Filters the raw HTML for the order summary section before it's displayed on your site.

add_filter( 'automator_order_summary_html_raw', $callback, 10, 2 );

Description

This filter hook allows developers to modify the raw HTML output for WooCommerce order summaries before it's displayed. It provides access to the generated HTML array and the order object. Use it to customize how order totals or other summary details are presented within Uncanny Automator recipes.


Usage

add_filter( 'automator_order_summary_html_raw', 'your_function_name', 10, 2 );

Parameters

$html (mixed)
This parameter holds the raw HTML output for the order summary, allowing for modifications before it's displayed.
$order (mixed)
This parameter holds the generated HTML for the order summary, which can be modified by the filter.

Return Value

The filtered value.


Examples

add_filter( 'automator_order_summary_html_raw', 'my_automator_modify_order_summary_html', 10, 2 );

/**
 * Modify the raw HTML for an order summary to include an additional piece of information.
 *
 * This function demonstrates how to add custom data to the order summary HTML
 * generated by Uncanny Automator. In this example, we'll add a custom meta field
 * if it exists for the order.
 *
 * @param array $html The array of HTML elements representing the order summary.
 * @param WC_Order $order The WooCommerce order object.
 * @return array The modified array of HTML elements.
 */
function my_automator_modify_order_summary_html( $html, $order ) {

    // Check if the order has a custom meta field we want to display.
    // Replace 'my_custom_order_meta_key' with your actual meta key.
    $custom_meta_value = $order->get_meta( 'my_custom_order_meta_key', true );

    if ( ! empty( $custom_meta_value ) ) {
        // Find the position where we want to insert our custom information.
        // This is a simplified example. In a real-world scenario, you might
        // need to parse the $html array more carefully to find the exact insertion point.
        // For this example, let's assume we want to add it before the closing </div>.
        $insertion_point = count( $html ) - 2; // Before the '</div>'

        // Prepare the HTML for our custom information.
        $custom_html_part = '
            <tr>
                <td class="automator-label">' . esc_html__( 'Custom Data:', 'your-text-domain' ) . '</td>
                <td class="automator-value">' . esc_html( $custom_meta_value ) . '</td>
            </tr>
        ';

        // Insert our custom HTML into the array.
        // We need to split the table row into two parts and insert our custom row in between.
        // This requires more precise parsing of the $html array if it's complex.
        // For simplicity, let's find the '</table>' tag and insert our row before it.
        $table_end_index = array_search( '</table>', $html );

        if ( $table_end_index !== false ) {
            // Insert our custom row after the last existing row and before the table closing tag.
            array_splice( $html, $table_end_index, 0, array( $custom_html_part ) );
        } else {
            // Fallback if table tag isn't found (unlikely for this hook).
            $html[] = $custom_html_part;
        }
    }

    return $html;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/woocommerce/tokens/wc-tokens.php:1127
src/integrations/wholesale-suite/tokens/wss-tokens.php:753
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:3039

$html[] = $td_right;
			$html[] = $order->get_formatted_order_total();
			$html[] = '</td>';
			$html[] = '</tr>';
		}
		$html[] = '</table>';
		$html[] = '</div>';
		$html   = apply_filters( 'automator_order_summary_html_raw', $html, $order );

		return implode( PHP_EOL, $html );
	}

	/**
	 * Method get_products_skus.
	 *


Scroll to Top