Hello,
I'm struggling to modify a plugin that adds an alternative
price field to the
item-post /
item-edit pages.
In it's current form, the plugin always shows the field regardless of the category selected, but I want to change it to be
category-dependant.
By looking at the plugin dev structure
here, I've managed to hook the plugin to categories (
t_plugin_category table), but I can't make the field show/hide based on the category selection...
Here is the plugin code that handles the field:
function osc_set_mrp_number() {
$detail = '';
if (osc_is_publish_page()) {
if (Session::newInstance()->_getForm('mrp') != '') {
$detail = Session::newInstance()->_getForm('mrp');
}
} else if (osc_is_edit_page()) {
if (Session::newInstance()->_getForm('mrp') != '') {
$detail = Session::newInstance()->_getForm('mrp');
} else {
$value = Modeldiscount::newInstance()->t_check_value(osc_item_id());
if (!empty($value)) {
$detail = $value['s_mrp'];
}
}
}
?>
<div class="form-group js-price">
<label class="col-sm-3 control-label" for="price"><?php _e('Market Price', 'mrp'); ?></label>
<div class="col-sm-3">
<input id="mrp" type="text" value="<?php echo osc_esc_html($detail); ?>" name="mrp"></input>
</div>
<div class="col-sm-3">
<?php ItemForm::currency_select(); ?>
</div>
</div>
<?php
}
function pre_post_store_value() {
Session::newInstance()->_setForm('mrp', Params::getParam("mrp"));
Session::newInstance()->_keepForm('mrp');
}
osc_add_hook('pre_item_post', 'pre_post_store_value');
The plugin's slug is
mrp_price, so I tried to add a category check, but this hides the field completely and doesn't show it when selecting the correct category:
if (osc_is_this_category('mrp_price', osc_item_category_id())) {
if ( Session::newInstance()->_getForm('mrp') != '' ) {
$detail['mrp'] = Session::newInstance()->_getForm('mrp');
}
}
What else could I try, as this is driving me crazy?
Thanks!