Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active October 12, 2020 14:02
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 plugin-republic/8796fcf40ece687092db31d6f1c9383b to your computer and use it in GitHub Desktop.
Save plugin-republic/8796fcf40ece687092db31d6f1c9383b to your computer and use it in GitHub Desktop.
Programmatically set whether a product should have a deposit option
<?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 );
@Dennis-teammade
Copy link

If I want to set it for all products in a categorie (example 'accesoires') how would that work...?

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