How would I use WooCommerce hooks in my plugin? Here is what I am trying to do:
add_filter('woocommerce_edit_product_columns', 'pA_manage_posts_columns');
function pA_manage_posts_columns($columns, $post_type = 'product') {
global $woocommerce;
if ( in_array( $post_type, array( 'product') ) ) {
$columns['offering_price'] = __( 'offering price', 'your_text_domain' ); // this offering price title
$columns['offering_qty'] = __( 'Qty', 'your_text_domain' ); // add the quantity title
}
unset($columns['name']);
return $columns;
Here is how I include WooCommerce in my plugin:
$ds = DIRECTORY_SEPARATOR;
$base_dir = realpath(dirname(__FILE__) . $ds . '..') . $ds;
$file = "{$base_dir}woocommerce{$ds}woocommerce.php";
include_once($file);
Still can’t get the output from
print_r($woocommerce);
You’re mixed the hook with the callback. The original call is in this file:
Your code should be:
Note that there’s no
post_type
parameter in the callback. The filter hook is already telling what the post type is:manage_edit-product_columns
.As Obmerk Kronen has pointed out, there’s no need to include any WooCommerce file, all its functionality is available to you already.