/** * Stock column in Manage Products page. * * @since 3.8.9 * @access private * @param object $post Post Object * @param int $post_id Post ID * @param boolean $has_variations Whether the product has variations */ function _wpsc_manage_products_column_stock($post, $post_id, $has_variations) { $stock = get_post_meta($post->ID, '_wpsc_stock', true); if ($stock == '') { $stock = __('N/A', 'wpsc'); } if ($has_variations) { echo '~ ' . wpsc_variations_stock_remaining($post->ID); return; } echo $stock; echo '<div id="inline_' . $post->ID . '_stock" class="hidden">' . $stock . '</div>'; }
function wpsc_stock_control_forms() { global $post, $wpdb, $variations_processor, $wpsc_product_defaults; $product_data = get_post_custom($post->ID); $product_data['meta'] = maybe_unserialize($product_data); foreach ($product_data['meta'] as $meta_key => $meta_value) { $product_data['meta'][$meta_key] = $meta_value[0]; } $product_meta = array(); if (!empty($product_data['_wpsc_product_metadata'])) { $product_meta = maybe_unserialize($product_data["_wpsc_product_metadata"][0]); } // this is to make sure after upgrading to 3.8.9, products will have // "notify_when_none_left" enabled by default if "unpublish_when_none_left" // is enabled. if (!isset($product_meta['notify_when_none_left'])) { $product_meta['notify_when_none_left'] = 0; if (!empty($product_meta['unpublish_when_none_left'])) { $product_meta['notify_when_none_left'] = 1; } } if (!isset($product_meta['unpublish_when_none_left'])) { $product_meta['unpublish_when_none_left'] = ''; } // Display live title if stock is set if (isset($product_data['meta']['_wpsc_stock']) && is_numeric($product_data['meta']['_wpsc_stock'])) { $live_title = '<em id="wpsc_product_stock_metabox_live_title" class="wpsc_metabox_live_title">'; $live_title .= sprintf('<p><span>%s</span> %s</p>', wpsc_format_number($product_data['meta']['_wpsc_stock'], 0), _x('left in stock', 'live preview of stock remaining in admin', 'wp-e-commerce')); $live_title .= '</em>'; echo $live_title; } if (!empty($product_meta['unpublish_when_none_left']) && !isset($product_meta['notify_when_none_left'])) { } ?> <label for="wpsc_sku"><abbr title="<?php esc_attr_e('Stock Keeping Unit', 'wp-e-commerce'); ?> "><?php esc_html_e('SKU:', 'wp-e-commerce'); ?> </abbr></label> <?php if (!isset($product_data['meta']['_wpsc_sku'])) { $product_data['meta']['_wpsc_sku'] = $wpsc_product_defaults['meta']['sku']; } ?> <br /> <input size='32' type='text' class='text' id="wpsc_sku" name='meta[_wpsc_sku]' value='<?php echo esc_html($product_data['meta']['_wpsc_sku']); ?> ' /> <br style="clear:both" /> <?php if (!isset($product_data['meta']['_wpsc_stock'])) { $product_data['meta']['_wpsc_stock'] = ''; } ?> <br /><input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' <?php if (is_numeric($product_data['meta']['_wpsc_stock'])) { echo 'checked="checked"'; } else { echo ''; } ?> name='meta[_wpsc_limited_stock]' /> <label for='add_form_quantity_limited' class='small'><?php esc_html_e('Product has limited stock', 'wp-e-commerce'); ?> </label> <?php if ($post->ID > 0) { if (is_numeric($product_data['meta']['_wpsc_stock'])) { ?> <div class='edit_stock' style='display: block;'> <?php } else { ?> <div class='edit_stock' style='display: none;'><?php } ?> <?php if (wpsc_product_has_children($post->ID)) { ?> <?php $stock = wpsc_variations_stock_remaining($post->ID); ?> <p><?php echo sprintf(__('This product has variations. To edit the quantity, please use the <a href="%s">Variation Controls</a> below.', 'wp-e-commerce'), '#wpsc_product_variation_forms'); ?> </p> <p><?php printf(_n("%s variant item in stock.", "%s variant items in stock.", $stock, 'wp-e-commerce'), $stock); ?> </p> <?php } else { ?> <div style="margin-bottom:20px;"> <label for="stock_limit_quantity"><?php esc_html_e('Quantity in stock', 'wp-e-commerce'); ?> </label> <input type='number' min="0" step="1" style="width:80px; margin-left:50px;" id="stock_limit_quantity" name='meta[_wpsc_stock]' size='3' value='<?php echo absint($product_data['meta']['_wpsc_stock']); ?> ' class='stock_limit_quantity' /> </div> <?php $remaining_quantity = wpsc_get_remaining_quantity($post->ID); $reserved_quantity = $product_data['meta']['_wpsc_stock'] - $remaining_quantity; if ($reserved_quantity) { echo '<p><em>'; printf(_n('%s of them is reserved for pending or recently completed orders.', '%s of them are reserved for pending or recently completed orders.', $reserved_quantity, 'wp-e-commerce'), $reserved_quantity); echo '</em></p>'; } ?> <?php } ?> <p><?php esc_html_e('When stock reduces to zero:', 'wp-e-commerce'); ?> </p> <div class='notify_when_none_left'> <input type='checkbox' id="notify_when_oos" name='meta[_wpsc_product_metadata][notify_when_none_left]' class='notify_when_oos'<?php checked($product_meta['notify_when_none_left']); ?> /> <label for="notify_when_oos"><?php esc_html_e('Notify site owner via email', 'wp-e-commerce'); ?> </label> </div> <div class='unpublish_when_none_left'> <input type='checkbox' id="unpublish_when_oos" name='meta[_wpsc_product_metadata][unpublish_when_none_left]' class='unpublish_when_oos'<?php checked($product_meta['unpublish_when_none_left']); ?> /> <label for="unpublish_when_oos"><?php esc_html_e('Unpublish product from website', 'wp-e-commerce'); ?> </label> </div> </div> <?php } else { ?> <div style='display: none;' class='edit_stock'> <?php esc_html_e('Stock Qty', 'wp-e-commerce'); ?> <input type='text' name='meta[_wpsc_stock]' value='0' size='10' /> <div style='font-size:9px; padding:5px;'> <input type='checkbox' class='notify_when_oos' name='meta[_wpsc_product_metadata][notify_when_none_left]' /> <?php esc_html_e('Email site owner if this Product runs out of stock', 'wp-e-commerce'); ?> <input type='checkbox' class='unpublish_when_oos' name='meta[_wpsc_product_metadata][unpublish_when_none_left]' /> <?php esc_html_e('Set status to Unpublished if this Product runs out of stock', 'wp-e-commerce'); ?> </div> </div> <?php } wp_nonce_field('update', 'wpsc_product_stock_nonce'); }
function wpsc_stock_control_forms() { global $post, $wpdb, $variations_processor, $wpsc_product_defaults; $product_data = get_post_custom($post->ID); $product_data['meta'] = maybe_unserialize($product_data); foreach ($product_data['meta'] as $meta_key => $meta_value) { $product_data['meta'][$meta_key] = $meta_value[0]; } $product_meta = array(); if (!empty($product_data["_wpsc_product_metadata"])) { $product_meta = maybe_unserialize($product_data["_wpsc_product_metadata"][0]); } // this is to make sure after upgrading to 3.8.9, products will have // "notify_when_none_left" enabled by default if "unpublish_when_none_left" // is enabled. if (!isset($product_meta['notify_when_none_left'])) { $product_meta['notify_when_none_left'] = 0; if (!empty($product_meta['unpublish_when_none_left'])) { $product_meta['notify_when_none_left'] = 1; } } if (!isset($product_meta['unpublish_when_none_left'])) { $product_meta['unpublish_when_none_left'] = ''; } if (!empty($product_meta['unpublish_when_none_left']) && !isset($product_meta['notify_when_none_left'])) { } ?> <label for="wpsc_sku"><abbr title="<?php esc_attr_e('Stock Keeping Unit', 'wpsc'); ?> "><?php esc_html_e('SKU:', 'wpsc'); ?> </abbr></label> <?php if (!isset($product_data['meta']['_wpsc_sku'])) { $product_data['meta']['_wpsc_sku'] = $wpsc_product_defaults['meta']['sku']; } ?> <br /> <input size='32' type='text' class='text' id="wpsc_sku" name='meta[_wpsc_sku]' value='<?php echo esc_html($product_data['meta']['_wpsc_sku']); ?> ' /> <br style="clear:both" /> <?php if (!isset($product_data['meta']['_wpsc_stock'])) { $product_data['meta']['_wpsc_stock'] = ''; } ?> <br /><input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' <?php if (is_numeric($product_data['meta']['_wpsc_stock'])) { echo 'checked="checked"'; } else { echo ''; } ?> name='meta[_wpsc_limited_stock]' /> <label for='add_form_quantity_limited' class='small'><?php esc_html_e('I have limited stock for this Product', 'wpsc'); ?> </label> <?php if ($post->ID > 0) { if (is_numeric($product_data['meta']['_wpsc_stock'])) { ?> <div class='edit_stock' style='display: block;'> <?php } else { ?> <div class='edit_stock' style='display: none;'><?php } ?> <?php if (wpsc_product_has_children($post->ID)) { ?> <?php $stock = wpsc_variations_stock_remaining($post->ID); ?> <p><?php esc_html_e('This Product has variations, to edit the quantity please use the Variation Controls below.', 'wpsc'); ?> </p> <p><?php printf(_n("%s variant item in stock.", "%s variant items in stock.", $stock, 'wpsc'), $stock); ?> </p> <?php } else { ?> <label for="stock_limit_quantity"><?php esc_html_e('Quantity:', 'wpsc'); ?> </label> <input type='text' id="stock_limit_quantity" name='meta[_wpsc_stock]' size='3' value='<?php echo $product_data['meta']['_wpsc_stock']; ?> ' class='stock_limit_quantity' /> <?php $remaining_quantity = wpsc_get_remaining_quantity($post->ID); $reserved_quantity = $product_data['meta']['_wpsc_stock'] - $remaining_quantity; if ($reserved_quantity) { ?> <p><em> <?php printf(_n('%s of them is reserved for pending or recently completed orders.', '%s of them are reserved for pending or recently completed orders.', $reserved_quantity, 'wpsc'), $reserved_quantity); ?> </em></p> <?php } ?> <?php } ?> <div class='notify_when_none_left'> <input type='checkbox' id="notify_when_oos" name='meta[_wpsc_product_metadata][notify_when_none_left]' class='notify_when_oos'<?php checked($product_meta['notify_when_none_left']); ?> /> <label for="notify_when_oos"><?php esc_html_e('Notify site owner if stock runs out', 'wpsc'); ?> </label> </div> <div class='unpublish_when_none_left'> <input type='checkbox' id="unpublish_when_oos" name='meta[_wpsc_product_metadata][unpublish_when_none_left]' class='unpublish_when_oos'<?php checked($product_meta['unpublish_when_none_left']); ?> /> <label for="unpublish_when_oos"><?php esc_html_e('Unpublish this Product if stock runs out', 'wpsc'); ?> </label> <p><em><?php esc_html_e('If stock runs out, this Product will not be available on the shop unless you untick this box or add more stock.', 'wpsc'); ?> </em></p> </div> </div> <?php } else { ?> <div style='display: none;' class='edit_stock'> <?php esc_html_e('Stock Qty', 'wpsc'); ?> <input type='text' name='meta[_wpsc_stock]' value='0' size='10' /> <div style='font-size:9px; padding:5px;'> <input type='checkbox' class='notify_when_oos' name='meta[_wpsc_product_metadata][notify_when_none_left]' /> <?php esc_html_e('Email site owner if this Product runs out of stock', 'wpsc'); ?> <input type='checkbox' class='unpublish_when_oos' name='meta[_wpsc_product_metadata][unpublish_when_none_left]' /> <?php esc_html_e('Set status to Unpublished if this Product runs out of stock', 'wpsc'); ?> </div> </div><?php } }
function wpsc_st_product_columns_data($post, $post_id, $is_parent) { $low_stock = get_option('wpsc_low_stock', 3); $stock = get_product_meta($post_id, 'stock', true); if ($is_parent) { $stock = wpsc_variations_stock_remaining($post_id); } $output = ''; if (is_numeric($stock)) { if ($stock > $low_stock) { $output .= '<span class="in_stock">' . __('In stock', 'wpsc_st') . '</span>'; if ($is_parent) { $output .= ' x ~' . $stock; } else { $output .= ' x ' . $stock; } } else { if ($stock <= 0) { $output .= '<span class="no_stock">' . __('Out of stock', 'wpsc_st') . '</span>'; } else { $output .= '<span class="low_stock">' . __('Low stock', 'wpsc_st') . '</span>'; if ($is_parent) { $output .= ' x ~' . $stock; } else { $output .= ' x ' . $stock; } } } } else { $output = ''; } if ($stock == '') { $stock = 0; } $output .= '<div id="inline_' . $post_id . '_stock_ind" class="hidden">' . esc_html($stock) . '</div>'; echo $output; }
function wpsc_stock_control_forms() { global $post, $wpdb, $variations_processor, $wpsc_product_defaults; $product_data = get_post_custom($post->ID); $product_data['meta'] = maybe_unserialize($product_data); foreach ($product_data['meta'] as $meta_key => $meta_value) { $product_data['meta'][$meta_key] = $meta_value[0]; } $product_meta = array(); if (!empty($product_data["_wpsc_product_metadata"])) { $product_meta = maybe_unserialize($product_data["_wpsc_product_metadata"][0]); } if (!isset($product_meta['unpublish_when_none_left'])) { $product_meta['unpublish_when_none_left'] = ''; } ?> <label for="wpsc_sku"><abbr title="<?php _e('Stock Keeping Unit', 'wpsc'); ?> "><?php _e('SKU:', 'wpsc'); ?> </abbr></label> <?php if (!isset($product_data['meta']['_wpsc_sku'])) { $product_data['meta']['_wpsc_sku'] = $wpsc_product_defaults['meta']['sku']; } ?> <br /> <input size='32' type='text' class='text' id="wpsc_sku" name='meta[_wpsc_sku]' value='<?php echo htmlentities(stripslashes($product_data['meta']['_wpsc_sku']), ENT_QUOTES, 'UTF-8'); ?> ' /> <br style="clear:both" /> <?php if (!isset($product_data['meta']['_wpsc_stock'])) { $product_data['meta']['_wpsc_stock'] = ''; } ?> <br /><input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' <?php if (is_numeric($product_data['meta']['_wpsc_stock'])) { echo 'checked="checked"'; } else { echo ''; } ?> name='meta[_wpsc_limited_stock]' /> <label for='add_form_quantity_limited' class='small'><?php _e('Este produto tem estoque limitado', 'wpsc'); ?> </label> <?php if ($post->ID > 0) { if (is_numeric($product_data['meta']['_wpsc_stock'])) { ?> <div class='edit_stock' style='display: block;'> <?php } else { ?> <div class='edit_stock' style='display: none;'><?php } ?> <?php if (wpsc_product_has_children($post->ID)) { ?> <?php $stock = wpsc_variations_stock_remaining($post->ID); ?> <p><?php _e('Este produto possui variações, para editar as quantidades use o controle de variações ao lado.', 'wpsc'); ?> </p> <p><?php printf(_n("%s variant item in stock.", "%s ítens de variação em estoque.", $stock, 'wpsc'), $stock); ?> </p> <?php } else { ?> <label for="stock_limit_quantity"><?php _e('Quantity:', 'wpsc'); ?> </label> <input type='text' id="stock_limit_quantity" name='meta[_wpsc_stock]' size='3' value='<?php echo $product_data['meta']['_wpsc_stock']; ?> ' class='stock_limit_quantity' /> <?php $remaining_quantity = wpsc_get_remaining_quantity($post->ID); $reserved_quantity = $product_data['meta']['_wpsc_stock'] - $remaining_quantity; if ($reserved_quantity) { ?> <p><em> <?php printf(_n('%s of them is reserved for pending or recently completed orders.', '%s of them are reserved for pending or recently completed orders.', $reserved_quantity, 'wpsc'), $reserved_quantity); ?> </em></p> <?php } ?> <?php } ?> <div class='unpublish_when_none_left'> <input type='checkbox' id="inform_when_oos" name='meta[_wpsc_product_metadata][unpublish_when_none_left]' class='inform_when_oos'<?php if ($product_meta['unpublish_when_none_left'] == 1) { echo ' checked="checked"'; } ?> /> <label for="inform_when_oos"><?php _e('Notifique o administrador caso o produto fique fora de estoque', 'wpsc'); ?> </label> </div> <p><em><?php _e('', 'wpsc'); ?> </em></p> </div> <?php } else { ?> <div style='display: none;' class='edit_stock'> <?php _e('Stock Qty', 'wpsc'); ?> <input type='text' name='meta[_wpsc_stock]' value='0' size='10' /> <div style='font-size:9px; padding:5px;'> <input type='checkbox' class='inform_when_oos' name='meta[_wpsc_product_metadata][unpublish_when_none_left]' /> <?php _e('If this Product runs out of stock set status to Unpublished & email site owner', 'wpsc'); ?> </div> </div><?php } }
/** * wpsc_additional_column_data. * * @access public * @param (array) $column * @return void * @todo Need to check titles / alt tags ( I don't think thumbnails have any in this code ) * @desc Switch function to generate columns the right way...no more UI hacking! * */ function wpsc_additional_column_data($column) { global $post; $is_parent = (bool) wpsc_product_has_children($post->ID); switch ($column) { case 'image': $attached_images = get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'post_parent' => $post->ID, 'orderby' => 'menu_order', 'order' => 'ASC')); if (isset($post->ID) && has_post_thumbnail($post->ID)) { echo get_the_post_thumbnail($post->ID, 'admin-product-thumbnails'); } else { if (!empty($attached_images)) { $attached_image = $attached_images[0]; $src = wp_get_attachment_url($attached_image->ID); ?> <div style='width:38px; height:38px; overflow:hidden;'> <img src='<?php echo $src; ?> ' alt='<?php _e('Drag to a new position', 'wpsc'); ?> ' width='38' height='38' /> </div> <?php } else { $image_url = WPSC_CORE_IMAGES_URL . "/no-image-uploaded.gif"; ?> <img src='<?php echo $image_url; ?> ' alt='<?php _e('Drag to a new position', 'wpsc'); ?> ' width='38' height='38' /> <?php } } break; case 'weight': if ($is_parent) { _e('N/A', 'wpsc'); } else { $product_data['meta'] = array(); $product_data['meta'] = get_post_meta($post->ID, ''); foreach ($product_data['meta'] as $meta_name => $meta_value) { $product_data['meta'][$meta_name] = maybe_unserialize(array_pop($meta_value)); } $product_data['transformed'] = array(); if (!isset($product_data['meta']['_wpsc_product_metadata']['weight'])) { $product_data['meta']['_wpsc_product_metadata']['weight'] = ""; } if (!isset($product_data['meta']['_wpsc_product_metadata']['weight_unit'])) { $product_data['meta']['_wpsc_product_metadata']['weight_unit'] = ""; } $product_data['transformed']['weight'] = wpsc_convert_weight($product_data['meta']['_wpsc_product_metadata']['weight'], "pound", $product_data['meta']['_wpsc_product_metadata']['weight_unit']); $weight = $product_data['transformed']['weight']; if ($weight == '') { $weight = '0'; } $unit = $product_data['meta']['_wpsc_product_metadata']['weight_unit']; switch ($unit) { case "pound": $unit = __(" lbs.", "wpsc"); break; case "ounce": $unit = __(" oz.", "wpsc"); break; case "gram": $unit = __(" g", "wpsc"); break; case "kilograms": case "kilogram": $unit = __(" kgs.", "wpsc"); break; } echo $weight . $unit; echo '<div id="inline_' . $post->ID . '_weight" class="hidden">' . $weight . '</div>'; } break; case 'stock': $stock = get_post_meta($post->ID, '_wpsc_stock', true); if ($stock == '') { $stock = __('N/A', 'wpsc'); } if (!$is_parent) { echo $stock; echo '<div id="inline_' . $post->ID . '_stock" class="hidden">' . $stock . '</div>'; } else { echo '~' . wpsc_variations_stock_remaining($post->ID); } break; case 'price': $price = get_post_meta($post->ID, '_wpsc_price', true); $has_var = '1'; if (!$is_parent) { echo wpsc_currency_display($price); echo '<div id="inline_' . $post->ID . '_price" class="hidden">' . trim($price) . '</div>'; $has_var = '0'; } else { echo wpsc_product_variation_price_available($post->ID) . '+'; } echo '<input type="hidden" value="' . $has_var . '" id="inline_' . $post->ID . '_has_var" />'; break; case 'sale_price': $price = get_post_meta($post->ID, '_wpsc_special_price', true); if (!$is_parent) { echo wpsc_currency_display($price); echo '<div id="inline_' . $post->ID . '_sale_price" class="hidden">' . $price . '</div>'; } else { echo wpsc_product_variation_price_available($post->ID) . '+'; } break; case 'SKU': $sku = get_post_meta($post->ID, '_wpsc_sku', true); if ($sku == '') { $sku = __('N/A', 'wpsc'); } echo $sku; echo '<div id="inline_' . $post->ID . '_sku" class="hidden">' . $sku . '</div>'; break; case 'cats': $categories = get_the_product_category($post->ID); if (!empty($categories)) { $out = array(); foreach ($categories as $c) { $out[] = "<a href='?post_type=wpsc-product&wpsc_product_category={$c->slug}'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>"; } echo join(', ', $out); } else { _e('Uncategorized', 'wpsc'); } break; case 'featured': $featured_product_url = wp_nonce_url("index.php?wpsc_admin_action=update_featured_product&product_id={$post->ID}", 'feature_product_' . $post->ID); ?> <a class="wpsc_featured_product_toggle featured_toggle_<?php echo $post->ID; ?> " href='<?php echo $featured_product_url; ?> ' > <?php if (in_array($post->ID, (array) get_option('sticky_products'))) { ?> <img class='gold-star' src='<?php echo WPSC_CORE_IMAGES_URL; ?> /gold-star.gif' alt='<?php _e('Unmark as Featured', 'wpsc'); ?> ' title='<?php _e('Unmark as Featured', 'wpsc'); ?> ' /> <?php } else { ?> <img class='grey-star' src='<?php echo WPSC_CORE_IMAGES_URL; ?> /grey-star.gif' alt='<?php _e('Mark as Featured', 'wpsc'); ?> ' title='<?php _e('Mark as Featured', 'wpsc'); ?> ' /> <?php } ?> </a> <?php break; case 'hidden_alerts': $product_alert = apply_filters('wpsc_product_alert', array(false, ''), $post); if (!empty($product_alert['messages'])) { $product_alert['messages'] = implode("\n", (array) $product_alert['messages']); } if ($product_alert['state'] === true) { ?> <img alt='<?php echo $product_alert['messages']; ?> ' title='<?php echo $product_alert['messages']; ?> ' class='product-alert-image' src='<?php echo WPSC_CORE_IMAGES_URL; ?> /product-alert.jpg' alt='' /> <?php } // If a product alert has stuff to display, show it. // Can be used to add extra icons etc if (!empty($product_alert['display'])) { echo $product_alert['display']; } break; } }