Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Created November 12, 2015 17:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bentasm1/9167fc3f6433e02cddcf to your computer and use it in GitHub Desktop.
Save bentasm1/9167fc3f6433e02cddcf to your computer and use it in GitHub Desktop.
WC Vendors Pro -- Change defaults for Stock Management / Quantity / Sold Individually
/* Credit to @criticalachievement */
// Changes the default value for manage stock checkbox to checked
add_filter( 'wcv_product_manage_stock', 'change_default_manage_stock' );
function change_default_manage_stock() {
$field['post_id'] = $post_id;
$field['id'] = '_manage_stock';
$field['wrapper_class'] = 'show_if_simple show_if_variable';
$field['label'] = __( 'Manage stock?', 'wcvendors-pro' );
$field['description'] = __( 'Enable stock management at product level', 'wcvendors-pro' );
$field['type'] = 'checkbox';
$field['value'] = 'yes'; // This checks the checkbox
return $field;
}
// Changes the default value for sold individually checkbox to checked
add_filter( 'wcv_product_sold_individually', 'change_default_sold_individually' );
function change_default_sold_individually() {
$field['post_id'] = $post_id;
$field['id'] = '_sold_individually';
$field['wrapper_class'] = 'show_if_simple show_if_variable';
$field['label'] = __( 'Sold Individually', 'wcvendors-pro' );
$field['desc_tip'] = 'true';
$field['description'] = __( 'Enable this to only allow one of this item to be bought in a single order', 'wcvendors-pro' );
$field['type'] = 'checkbox';
$field['value'] = 'yes'; // This checks the checkbox
return $field;
}
// Changes the default value for stock qty to 99
add_filter( 'wcv_product_stock_qty', 'change_default_stock_qty' );
function change_default_stock_qty() {
$field['post_id'] = $post_id;
$field['id'] = '_stock';
$field['label'] = __( 'Stock Qty', 'wcvendors-pro' );
$field['wrapper_start'] = '<div class="all-100">';
$field['wrapper_end'] = '</div>';
$field['desc_tip'] = 'true';
$field['description'] = __( 'Stock quantity.', 'wcvendors-pro' );
$field['type'] = 'number';
$field['data_type'] = 'stock';
$field['custom_attributes']['step'] = 'any';
$field['value'] = '99'; // This sets the quantity
return $field;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment