automator_woocommerce_order_summary_link_to_line_item
Filters whether to link WooCommerce order items to the product in the order summary.
add_filter( 'automator_woocommerce_order_summary_link_to_line_item', $callback, 10, 3 );
Description
Filters the order summary link to a line item in WooCommerce. Developers can use this hook to customize or disable the default behavior of linking order items, allowing for custom navigation or data presentation within the order summary. It's important to note the parameters provided, including the product, item, and order objects, for targeted manipulation.
Usage
add_filter( 'automator_woocommerce_order_summary_link_to_line_item', 'your_function_name', 10, 3 );
Parameters
-
$product(mixed) - This parameter controls whether a link to the line item should be displayed.
-
$item(mixed) - This parameter contains the WooCommerce product object associated with the order item.
-
$order(mixed) - This parameter contains the WooCommerce order item object.
Return Value
The filtered value.
Examples
// Prevent the product title from being linked to the product permalink in the order summary
add_filter( 'automator_woocommerce_order_summary_link_to_line_item', 'my_automator_disable_order_item_link', 10, 4 );
function my_automator_disable_order_item_link( $should_link, $product, $item, $order ) {
// This filter controls whether the product title in the order summary is linked to the product's permalink.
// For this example, we'll always return false to prevent the link.
// In a real-world scenario, you might check for specific products, order statuses, or user roles.
return false;
}
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:1058
src/integrations/wholesale-suite/tokens/wss-tokens.php:685
uncanny-automator-pro/src/integrations/woocommerce/tokens/wc-pro-tokens.php:2971
$html[] = '<tr class="order_item">';
$title = $product->get_title();
if ( $item->get_variation_id() ) {
$variation = new WC_Product_Variation( $item->get_variation_id() );
$variation_name = implode( ' / ', $variation->get_variation_attributes() );
$title = apply_filters( 'automator_woocommerce_order_summary_line_item_title', "$title - $variation_name", $product, $item, $order );
}
if ( true === apply_filters( 'automator_woocommerce_order_summary_link_to_line_item', true, $product, $item, $order ) ) {
$title = sprintf( '<a style="color: %s; vertical-align: middle; padding: 12px 0; text-align: left;" href="%s">%s</a>', $td_text_colour, $product->get_permalink(), $title );
}
$html[] = sprintf( '%s %s</td>', $td, $title );
$html[] = $td . $item->get_quantity() . '</td>';
$html[] = $td . wc_price( $item->get_total() ) . '</td>';
$html[] = '</tr>';
}