Filter Uncanny Redemption Codes

ulc_wc_email_codes_table_position_order_table

Filters the position of the "Codes" table within WooCommerce order emails, allowing custom placement.

add_filter( 'ulc_wc_email_codes_table_position_order_table', $callback, 10, 1 );

Description

This filter allows developers to control the placement of the codes table within WooCommerce order emails. By default, it appears after the order table, but you can change this to 'before' to position it earlier in the email content.


Usage

add_filter( 'ulc_wc_email_codes_table_position_order_table', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Filter to change the position of the codes table in WooCommerce emails.
 *
 * By default, the codes table is displayed 'after' the order table.
 * This filter allows developers to move it to the 'before' position if needed.
 *
 * @param string $position The position where the codes table should be displayed.
 *                         Accepts 'after' (default) or 'before'.
 * @return string The desired position for the codes table.
 */
add_filter( 'ulc_wc_email_codes_table_position_order_table', function( $position ) {
    // Example: Conditionally change the position based on the order ID.
    // Let's say we want to display the codes table before the order table
    // for orders with an ID greater than 100.
    global $woocommerce; // Access WooCommerce global if needed, though often available in email context.

    // It's important to note that $order is typically available within the hook
    // that *uses* this $position filter. This example assumes a context where
    // an order object or ID might be accessible. If not, this logic would
    // need to be adapted. For a general filter, you might not have order-specific data.

    // For demonstration, let's simulate a condition. In a real scenario,
    // you'd likely have access to the current order within the hook that
    // triggers the email content.
    // As a fallback, if no specific order context is available, we stick to the default.
    $new_position = $position; // Start with the default.

    // Hypothetical: If you were in a context where you could check the order ID:
    // if ( isset( $order ) && $order instanceof WC_Order && $order->get_id() > 100 ) {
    //     $new_position = 'before';
    // }

    // For this standalone filter example, let's just show a basic override.
    // Let's say we *always* want it before for a specific client's site.
    // $new_position = 'before';

    // Returning the original position if no specific conditions are met.
    return $new_position;
}, 10, 1 );

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/classes/integrations/woocommerce/class-woo-automator-codes.php:84

);

			add_action(
				'init',
				function () {
					if ( apply_filters( 'ulc_wc_email_include_codes_table', true ) ) {
						// Check whether we have to add the codes table before or after the order table
						$position = apply_filters( 'ulc_wc_email_codes_table_position_order_table', 'after' );

						$email_codes_table_hook = 'woocommerce_email_after_order_table';
						if ( $position === 'before' ) {
							$email_codes_table_hook = 'woocommerce_email_before_order_table';
						}

						add_action(


Scroll to Top