I want to hide or remove a column from the cart of woocommerce, Im making a plugin for woocommerce so it wouldn't be good to modify directly cart.php or functions.php (which would be the solution) but when the woocommerce plugin release an update the code will be gone, right now i just could hide the item for price but not the entire column.
add_filter( 'woocommerce_cart_item_price', '__return_empty_string' );
Aditionally to this I could do it with CSS display:none
but people will be watch the items if they inspect the code, currently the cart is like this
.
Do you know how to hide the entire price column from the cart using hooks, thanks.
MY ANSWER :
With the help of Ben HartLenn I add to my plugin this code in order to replace the cart.php for my plugin's cart.php and some other file I need to replace
define( 'PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
add_filter( 'woocommerce_locate_template', 'plugin_locate_template', 10, 3 );
function plugin_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) $template_path = $woocommerce->template_url;
$plugin_path = PLUGIN_DIR . '/woocommerce/';
$template = locate_template(
array(
$template_path . $template_name,
$template_name
)
);
// Get the template from this plugin, if it exists
if ( ! $template && file_exists( $plugin_path . $template_name ) )
$template = $plugin_path . $template_name;
// Use default template
if ( ! $template )
$template = $_template;
// Return what we found
return $template;
}
Now I create in this case the folder cart and inside of it a cart.php file modified by me deleting the column Price and Total, it works with any file you need to replace.
You create that file on
/plugins/yourplugin/woocommerce/cart/cart.php
and the code will automatically replace the default woocommerce cart.php for your file, works with any file is inside woocommerce/templates/, that way you'll have your own customize woocommerce template files.
If this solution doesn't work and this code is not loading your own customized files it might be because the template (like avada for example) is already replacing the cart.php or someother file, check out the path
/themes/your_theme/woocommerce
To be sure the template is not replacing the same file you try to replacing with your plugin.
Thanks Ben for your help :D