Quantcast
Channel: WordPress.org Forums » [WooCommerce] Support
Viewing all articles
Browse latest Browse all 102102

nyenius on "[Plugin: WooCommerce - excelling eCommerce] Updating Product Category based on stock status in single product view"

$
0
0

This what i've done so far, and it works.

add_action('woocommerce_before_single_product', 'your_function_name');

function your_function_name() {

$postid = get_the_ID();
$post_custom = get_post_custom($postid);
$current_stock = get_post_meta($postid, '_stock', 1);

if($current_stock < 1 ){
// delete all product_cat related to this product
wp_set_object_terms( $postid, NULL, 'product_cat' );
// Stock is empty, so we set to "preorder" category (mine is 15)
wp_set_object_terms( $postid, array(15), 'product_cat' );

}else{
// // delete all product_cat related to this product
wp_set_object_terms( $postid, NULL, 'product_cat' );
// Stock is empty, so we set to "Ready Stock" category (mine is 14)
wp_set_object_terms( $postid, array(14), 'product_cat' );
}

And for specific product category, I use tags.


Viewing all articles
Browse latest Browse all 102102

Trending Articles