I’m having trouble disabling a function in the Woocommerce Force Sells extension. The function adds some text under the buy button on the frontend product page, that I would like to remove.
I think I have found the function in question in the woocommerce-force-sells.php file:
/**
* Displays information of what linked products that will get added when current
* product is added to cart.
*/
public function show_force_sell_products() {
global $post;
$product_ids = $this->get_force_sell_ids( $post->ID, array( 'normal', 'synced' ) );
$titles = array();
// Make sure the products still exist and don't display duplicates.
foreach( array_values( array_unique( $product_ids ) ) as $key => $product_id ) {
$product = wc_get_product( $product_id );
if ( $product && $product->exists() && 'trash' !== $product->get_status() ) {
$titles[] = version_compare( WC_VERSION, '3.0', '>=' ) ? $product->get_title() : get_the_title( $product_id );
}
}
if ( ! empty( $titles ) ) {
echo '<div class="clear"></div>';
echo '<div class="wc-force-sells">';
echo '<p>' . __( 'This will also add the following products to your cart:', 'woocommerce-force-sells' ) . '</p>';
echo '<ul>';
foreach ( $titles as $title ) {
echo '<li>' . $title . '</li>';
}
echo '</ul></div>';
}
}
I have looked at https://codex.wordpress.org/Function_Reference/remove_action but I can’t really figure out how to employ that in the code above.
Thanks a lot in advance!
2
Answers
You cannot remove a function, you can only prevent it from being executed. That is not the same as removing an action though. However, if you want to remove text from a button, you are probably better off changing the template file that adds the button to the page.
Here is some more information about changing the template: https://docs.woocommerce.com/document/template-structure/
The easy way to do this is by hiding the content from the page. Look for the class and add
display:none ;
to that class in css.
or
you can edit it in woocommerce template files. it is hard to find from which page it is coming from (look in all possible pages in templates ). once you find it remember to copy that template to child theme.(create a folder in child theme named as woocommerce—add folder path if there is some in actual location). or else you will loose all the edits when woocommerce is updated.
easy way is just hiding it from css