Created
February 3, 2018 09:14
-
-
Save shivapoudel/eff338766ccb34c8c1d31ddb3d85ec98 to your computer and use it in GitHub Desktop.
WooCommerce - Prevent order view link being triggered on row click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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