Last active
October 12, 2020 14:02
-
-
Save plugin-republic/8796fcf40ece687092db31d6f1c9383b to your computer and use it in GitHub Desktop.
Programmatically set whether a product should have a deposit option
This file contains 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 | |
/** | |
* Programmatically set whether a product should have a deposit option | |
* Set the global value for 'Accept Deposits' to 'Some Products' | |
*/ | |
function prefix_product_has_deposit( $has_deposit, $product_id ) { | |
// All the products in this list will not have a deposit option | |
if( in_array( $product_id, array( 123, 456, 789 ) ) { | |
$has_deposit = false; | |
} else { | |
$has_deposit = true; | |
} | |
return $has_deposit; | |
} | |
add_filter( 'wcdpp_product_has_deposit', 'prefix_product_has_deposit', 10, 2 ); | |
/** | |
* Programmatically set whether a product should have a deposit option | |
* Set the global value for 'Accept Deposits' to 'Some Products' | |
*/ | |
function prefix_product_has_deposit_by_category( $has_deposit, $product_id ) { | |
// All the products in this list will not have a deposit option | |
if( has_term( array( 'fruit' ), 'product_cat', $product_id ) ) { | |
$has_deposit = false; | |
} else { | |
$has_deposit = true; | |
} | |
return $has_deposit; | |
} | |
add_filter( 'wcdpp_product_has_deposit', 'prefix_product_has_deposit_by_category', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I want to set it for all products in a categorie (example 'accesoires') how would that work...?