Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Mass Price Update for Shopp
function vol_price_css() {
$theme_dir = get_bloginfo('template_directory');
<style type="text/css">
.shopp h2.voc_title {padding: 12px 15px 25px 0;}
.icon32 {background: url(<?php echo $theme_dir;?>/lib/img/shopp32.png) no-repeat scroll 0 0 transparent;}
.vcc_price_update_btn { position:absolute; top:47px; left:400px;}
table.price-editor tr.headers th{font-weight:bold;}
table.price-editor tr.even {background:#eeeeee;}
table.price-editor tr.odd {background:#ffffff;}
table.price-editor td.price input {width:45px; text-align:center;}
<?php }
add_action( 'admin_head', 'vol_price_css' );
// price page
class volcanic_price_edit_screen{
function __construct(){
add_action('shopp_init', array(&$this, 'init'));
function init(){
add_action('admin_menu', array(&$this, 'add_menu'));
function add_menu(){
global $Shopp;
$ShoppMenu = $Shopp->Flow->Admin->MainMenu; //this is our Shopp menu handle
add_submenu_page($ShoppMenu, 'Price Editor', 'Price Editor',(defined('SHOPP_USERLEVEL') ? SHOPP_USERLEVEL : 'manage_options'), 'price-editor', array($this, 'vol_price_screen'));
function vol_price_screen(){
// declare global DB
global $wpdb;
// define custom tables
$wpdb->shopp_product = $wpdb->prefix.'shopp_product';
$wpdb->shopp_price = $wpdb->prefix.'shopp_price';
if($_POST['submit']=="Update Prices"){
$price_tmp = $_POST['price'];
foreach($price_tmp as $key => $value) {
$wpdb->query("UPDATE $wpdb->shopp_price SET price = '$value' WHERE id = '$key'");
$message = '<div class="updated fade below-h2" id="message"><p>Prices have been updated successfully.</p></div>';
echo $message;
// prepare product list query
$shopp_product_query = $wpdb->prepare("
SELECT,,, ps.product, ps.label, ps.price
FROM $wpdb->shopp_product pd
INNER JOIN $wpdb->shopp_price ps
ON = ps.product
WHERE ps.price != '0.000000'
ORDER BY, ps.label ASC
$shopp_products = $wpdb->get_results($shopp_product_query);
// prepare update table layout
echo '<div class="wrap shopp">';
echo '<div class="icon32"></div>';
echo '<h2 class="voc_title">Bulk Price Editor</h2>';
<form name="shopp_price_update" id="shopp_price_update" method="post" action="">
<div class="vcc_price_update_btn"><input class="button-primary" type="submit" name="submit" value="<?php _e('Update Prices') ?>"></div>
<table class="widefat price-editor" cellspacing="0">
<tr class="headers">
<th scope='col'>Product Name</th>
<th scope='col'>Variation</th>
<th scope='col'>Price</th>
<tr class="headers">
<th scope='col'>Product Name</th>
<th scope='col'>Variation</th>
<th scope='col'>Price</th>
<tbody id="price-editor-table">
foreach ($shopp_products as $shopp_product) :
$prod_name = $shopp_product->name;
$price_lbl = $shopp_product->label;
$price_amt = $shopp_product->price;
$price_id = $shopp_product->id;
$even_odd = ( 'odd' != $even_odd ) ? 'odd' : 'even';
echo '<tr class="'.$even_odd.'">';
// echo '<td>'.$price_id .'</td>';
echo '<td class="name">'.$prod_name .'</td>';
echo '<td class="variation">'.$price_lbl .'</td>';
echo '<td class="price"><input type="text" name="price['.$price_id .']" class="price" value="'.number_format($price_amt, 2, '.', '') .'" /></td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';
echo '</form>';
echo '</div>';
} // end class
$priceEditPage = new volcanic_price_edit_screen();

Is this compatible with Shopp

norcross commented Aug 1, 2012

It should be. I haven't tested it with 1.2 though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.