Notify users of no variations but leave status as is.

Closes #9713
This commit is contained in:
Mike Jolley 2015-12-03 10:14:00 +00:00
parent 8f951d449a
commit 12db1d4637
4 changed files with 6 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -157,7 +157,7 @@
}
}
#variable_product_options #message {
#variable_product_options #message, #variable_product_options .notice {
margin: 10px;
}

View File

@ -84,7 +84,7 @@ class WC_Admin_Meta_Boxes {
if ( ! empty( $errors ) ) {
echo '<div id="woocommerce_errors" class="error">';
echo '<div id="woocommerce_errors" class="error notice is-dismissible">';
foreach ( $errors as $error ) {
echo '<p>' . wp_kses_post( $error ) . '</p>';

View File

@ -719,12 +719,10 @@ class WC_Product_Variable extends WC_Product {
'post_status' => 'publish'
) );
// No published variations - update parent post status. Use $wpdb to prevent endless loop on save_post hooks.
if ( ! $children && get_post_status( $product_id ) == 'publish' ) {
$wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $product_id ) );
// No published variations - product won't be purchasable.
if ( ! $children && 'publish' === get_post_status( $product_id ) ) {
if ( is_admin() ) {
WC_Admin_Meta_Boxes::add_error( __( 'This variable product has no active variations so cannot be published. Changing status to draft.', 'woocommerce' ) );
WC_Admin_Meta_Boxes::add_error( __( 'This variable product has no active variations. Add or enable variations to allow this product to be purchased.', 'woocommerce' ) );
}
// Loop the variations