Last active
March 19, 2025 14:15
-
-
Save webdados/a5260228e110a2b6ac1db8109f5b999c to your computer and use it in GitHub Desktop.
Example usage of Feed KuantoKusta para WooCommerce add-on PRO adjust price filters
This file contains hidden or 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 | |
// Example 1 | |
// Do not adjust any KuantoKusta price for products belonging to categories 90 and 333 | |
add_filter( 'kuantokusta_adjust_product_regular_price', 'my_kk_adjust_price_filter', 10, 2 ); | |
add_filter( 'kuantokusta_adjust_product_current_price', 'my_kk_adjust_price_filter', 10, 2 ); | |
add_filter( 'kuantokusta_adjust_variation_regular_price', 'my_kk_adjust_price_filter', 10, 2 ); | |
add_filter( 'kuantokusta_adjust_variation_current_price', 'my_kk_adjust_price_filter', 10, 2 ); | |
function my_kk_adjust_price_filter( $price, $product ) { | |
$categories_not_to_adjust_price = array( | |
90, | |
333, | |
); | |
foreach( $categories_not_to_adjust_price as $category_id ) { | |
if ( has_term( $category_id, 'product_cat', $product->get_id() ) ) { | |
return false; | |
} | |
} | |
return true; | |
} | |
// Example 2 | |
// Adjust any KuantoKusta price only for products belonging to categories 90 and 333 | |
add_filter( 'kuantokusta_adjust_product_regular_price', 'my_kk_adjust_price_filter_2', 10, 2 ); | |
add_filter( 'kuantokusta_adjust_product_current_price', 'my_kk_adjust_price_filter_2', 10, 2 ); | |
add_filter( 'kuantokusta_adjust_variation_regular_price', 'my_kk_adjust_price_filter_2', 10, 2 ); | |
add_filter( 'kuantokusta_adjust_variation_current_price', 'my_kk_adjust_price_filter_2', 10, 2 ); | |
function my_kk_adjust_price_filter_2( $price, $product ) { | |
$categories_to_adjust_price = array( | |
90, | |
333, | |
); | |
foreach( $categories_to_adjust_price as $category_id ) { | |
if ( has_term( $category_id, 'product_cat', $product->get_id() ) ) { | |
return true; | |
} | |
} | |
return false; | |
} | |
// Example 3 | |
// Do not adjust only variation regular prices for variations which price is above or equal to 100€ | |
// Be aware that if you do this only for the regular price, the current/sale price may be above the regular (for example if no sale is set, normally regular=current), so you probably want to use the same function also for kuantokusta_adjust_variation_current_price or activet the "Avoid crurrent price higher than regular price" option | |
add_filter( 'kuantokusta_adjust_variation_regular_price', 'my_kk_adjust_price_filter_3', 10, 3 ); | |
function my_kk_adjust_price_filter_3( $price, $product, $variation ) { | |
$regular_price_with_tax = wc_get_price_including_tax( $variation, array( 'price' => $variation->get_regular_price() ) ); | |
if ( $regular_price_with_tax >= 100 ) { | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment