Skip to content

Instantly share code, notes, and snippets.

@shivapoudel
Created February 3, 2018 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivapoudel/eff338766ccb34c8c1d31ddb3d85ec98 to your computer and use it in GitHub Desktop.
Save shivapoudel/eff338766ccb34c8c1d31ddb3d85ec98 to your computer and use it in GitHub Desktop.
WooCommerce - Prevent order view link being triggered on row click
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
if ( class_exists( 'WooCommerce' ) ) {
add_action( 'post_class', 'wc_order_post_class', 20, 3 );
}
/**
* Add extra post class for orders.
*
* Add the 'no-link' class to prevent order view link.
*
* @param array $classes Current classes.
* @param string|array $class Additional class.
* @param int $post_id Post ID.
* @return array
*/
function wc_order_post_class( $classes, $class = '', $post_id = '' ) {
if ( ! $post_id || ! in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ), true ) ) {
return $classes;
}
$order = wc_get_order( $post_id );
if ( $order ) {
$classes[] = 'no-link';
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment