Last active
March 7, 2022 12:23
-
-
Save cristianstan/027eb591b928c3e6ae91cc90278a8e16 to your computer and use it in GitHub Desktop.
WP List Table: Column.php sortable custom field
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 | |
// For iBid Auctions theme: https://themeforest.net/item/ibid-multi-vendor-auctions-woocommerce-theme/24923136 | |
// WP List Table: Column | |
add_action('manage_product_posts_custom_column', 'ibid_show_columns'); | |
function ibid_show_columns($name) { | |
global $post; | |
switch ($name) { | |
case 'shipping_country': | |
$shipping_country = get_post_meta($post->ID, '_shipping_country', true); | |
if (isset($shipping_country) && !empty($shipping_country)) { | |
echo $shipping_country; | |
} | |
break; | |
} | |
} | |
// Displaying the values | |
add_filter('manage_edit-product_columns', 'ibid_columns'); | |
function ibid_columns($columns) { | |
$columns['shipping_country'] = 'Shipping Country'; | |
return $columns; | |
} | |
// Sortable | |
add_filter( 'manage_edit-product_sortable_columns', 'ibid_sortable_date_column' ); | |
function ibid_sortable_date_column( $columns ) { | |
$columns['shipping_country'] = 'Shipping Country'; | |
return $columns; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment