Prevent variable products without variations from being posted and show error in admin. Closes #3763

This commit is contained in:
Mike Jolley 2013-09-24 16:37:51 +01:00
parent b5a798c9af
commit de9bc28b43
1 changed files with 8 additions and 0 deletions

View File

@ -488,6 +488,14 @@ class WC_Product_Variable extends WC_Product {
do_action( 'woocommerce_variable_product_sync', $product_id );
wc_delete_product_transients( $product_id );
} elseif ( get_post_status( $product_id ) == 'publish' ) {
// No published variations - update parent post status. Use $wpdb to prevent endless loop on save_post hooks.
global $wpdb;
$wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $product_id ) );
if ( is_admin() )
WC_Admin_Meta_Boxes::add_error( __( 'This variable product has no active variations and will not be published.', 'woocommerce' ) );
}
}
}