Skip to content

Instantly share code, notes, and snippets.

@somewherewarm-snippets
Last active November 17, 2021 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somewherewarm-snippets/a8fe98be1885025192b2ebdebe8c7b4b to your computer and use it in GitHub Desktop.
Save somewherewarm-snippets/a8fe98be1885025192b2ebdebe8c7b4b to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce Composite Products - Sale Status Tweak
* Plugin URI: https://woocommerce.com/products/composite-products/
* Description: Prevents Composite Products with component discounts from appearing as on-sale.
* Version: 1.0
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 4.1
* Tested up to: 5.3
*
* Copyright: © 2021 Automattic.
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'woocommerce_product_is_on_sale', 'wc_cp_component_discounts_sale_status', 10, 2 );
function wc_cp_component_discounts_sale_status( $on_sale, $product ) {
if ( $on_sale && 'composite' === $product->get_type() && $product->contains( 'priced_individually' ) ) {
$product = new WC_Product_Simple( $product->get_id() );
$on_sale = $product->is_on_sale();
}
return $on_sale;
}
@hheal
Copy link

hheal commented Sep 30, 2020

I have just put this in place, and it no longer seems to be working. If you are able to update it, it would be greatly appreciated!
Thanks :)

@robertoalmendral
Copy link

Hi there, this sniper is not working?

Someone can help us and fix it?

Thanks.

@somewherewarm-snippets
Copy link
Author

Hello there,

I tested the snippet locally and it works as expected!
When a Composite Product contains one or more Components with a discount, a 'Sale!' badge shows up by default on the product page: https://a.cl.ly/2NuEj485. When I enable this snippet, this badge is removed: https://a.cl.ly/Qwu9kgXB.

If you don't see the same on your site, can you please open a ticket for Composite Products from your WooCommerce.com account? We'd be happy to take a closer look!

@robertoalmendral
Copy link

Hi there, thank you for testing.

I can see that the badge was remove, but the price is the same. We want that the sale products when they are in composite the price to buy will be the regular price, not sale price. Sale price just if you are buying just this product. For example. Could you help us?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment