Right, I've got WordPress E-commerce installed on WordPress and I need to add additional columns to the post type.
I've done some investigating. It appears that E-commerce just submits a post type called "Products" and changes the columns in order to add things like Price etc.
I need to add another input. Just a little checkbox that the admin can set to true or false as they add a product. The only problem for me at the moment is finding where exactly to do this.
I think I've found the WordPress E-Commerce post type column settings, but obviously just adding an additional one isn't working.
/wp-content/plugins/wp-e-commerce/wpsc-admin/display-items.page.php
function wpsc_additional_column_names( $columns ){
$columns = array();
$columns['cb'] = '';
$columns['image'] = '';
$columns['title'] = __('Name', 'wpsc');
$columns['stock'] = __('Stock', 'wpsc');
$columns['price'] = __('Price', 'wpsc');
$columns['sale_price'] = __('Sale', 'wpsc');
$columns['SKU'] = __('SKU', 'wpsc');
$columns['weight'] = __('Weight', 'wpsc');
$columns['cats'] = __('Categories', 'wpsc');
$columns['featured'] = '';
$columns['hidden_alerts'] = '';
$columns['date'] = __('Date', 'wpsc');
return $columns;
}
Don't edit the core files. You can add custom metaboxes to WP e-Commerce's Products post type just as you would any other post type.
My preferred solution is to use Custom Metaboxes and Fields for WordPress
This sample function will output a checkbox on products using the above plugin (note 'pages' => array('wpsc-product'), this targets products only):
function base_meta_boxes_ba($meta_boxes) {
/**
* Page Options meta box
*/
$meta_boxes[] = array(
'id' => 'product_options',
'title' => 'Extra Product Options',
'pages' => array('wpsc-product'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => 'Test Checkbox',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_checkbox',
'type' => 'checkbox'
),
)
);
return $meta_boxes;
}
add_filter('cmb_meta_boxes', 'base_meta_boxes_ba');
Related
My goal is to get a signed-in user to select a color( via front end form and saved in ACF user meta field group) that will be applied to another user meta field inside a repeater. The field must be the same for each row inside the repeater ( for front-end design reasons ). I am using ACF pro, and a plugin called ACF Front end admin (let's call it FEA from now on) for the front-end form. I'm pretty new to PHP and have referenced ACF & FEA's s documentation, which can be found below, spin up a custom function. I am currently running this through the code snippets plugin if this helps. I've run an error log and nothing related to this shows. Tried running this through wp-config and it crashes my site.
Front end admin documentation
ACF documentation - update sub field
ACF documentation - getting values from a user
Edit, Additional information:
ACF Field composition of 'button color' (color of the buttons that user wants displayed in front end, and saved as user meta):
acf_add_local_field_group(array(
'key' => 'group_60000aaa00000',
'title' => 'Color Selector',
'fields' => array(
array(
'key' => 'field_60000aaa00000',
'label' => 'Button color',
'name' => 'button_color',
'type' => 'color_picker',
Button color in repeater field that needs to updated based on the above mentioned 'button_color' meta value:
acf_add_local_field_group(array(
'key' => 'group_70000bbb00000',
'title' => 'front end user profile',
'fields' => array(
array(
'key' => 'field_70000bbb00000',
'label' => 'Quick Link selector',
'name' => 'quick_link_selector',
'type' => 'repeater',
),
array(
'key' => 'field_70000ccc00000',
'label' => 'repeater button color',
'name' => 'repeater_button_color',
'type' => 'text',
The title of the forum is: "QL color selector form" (created through the FEA plugin) and has a short code of [frontend_admin form="3030"] if this helps.
I'm running the following code with no luck and would really appreciate any help!
/// Hooks into any(?) form and does something
add_action('acf_frontend/save_user', 'retrieve_colors_2_update', 10, 2);
function retrieve_colors_2_update( $form, $user_id ) {
$user = get_user_by('ID',$user_id);
//get important fields
$btn_color = get_field('button_color', 'user_' .$user_id);
//// update a repeater loop (ACF)
if( have_rows('quick_link_selector', 'user_'.$user_id) ) {
$i = 0;
while( have_rows('quick_link_selector') ) {
the_row();
$i++;
update_sub_field('repeater_button_color', $btn_color );
}
}
}
I'm trying to populate a checkbox ACF field with the various post types of a WP site. This is for a plugin, so the post types will vary based on the location of install.
By default, the plugin uses pages and posts as it's post types, but need to give user option to use checkboxes to select other CPT's on the site. How can I populate the checkbox field with the list of all CPT's on a site. Here is my current section of PHP code to load the field within the plugin
array (
'key' => 'field_56e6d87b6c7be',
'label' => 'Add to Custom Post Types',
'name' => 'fb_pixel_cpt_select',
'type' => 'checkbox',
'instructions' => 'Select which Custom Post Types you would like to use.',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
),
'default_value' => array (
),
'layout' => 'vertical',
'toggle' => 0,
),
You could use the ACF load field function here to auto populate your field. See more here: http://www.advancedcustomfields.com/resources/acfload_field/
Then, using the Wordpress get_post_types call (https://codex.wordpress.org/Function_Reference/get_post_types) you could retrieve those values and populate your field like this.
add_filter('acf/load_field/name=fb_pixel_cpt_select', 'acf_load_post_types');
function acf_load_post_types($field)
{
foreach ( get_post_types( '', 'names' ) as $post_type ) {
$field['choices'][$post_type] = $post_type;
}
// return the field
return $field;
}
Make sure that your field is already created before you try to populate it though.
This will create a select field for your ACF block or whatever that has all the post types except those that don't have a nav menu (such as the attachment post type).
add_filter('acf/load_field/name=select_post_type', 'yourprefix_acf_load_post_types');
/*
* Load Select Field `select_post_type` populated with the value and labels of the singular
* name of all public post types
*/
function yourprefix_acf_load_post_types( $field ) {
$choices = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
foreach ( $choices as $post_type ) :
$field['choices'][$post_type->name] = $post_type->labels->singular_name;
endforeach;
return $field;
}
When I need to do this (choose from list of post types) I would be creating a list of posts based on post-type to feed into WP Query. So I use a select field in ACF, and add the post type names into the select options when creating the field, e.g.
posts : Posts
which I then use in the arguments for the WP Query, like so:
$theselectfield = get_field('theselectfield');
Then use it in the arguement of the query:
$args = array(
'post_type' => $theselectfield,
'some_other' => 'argument',
);
I'm new on Magento and I have problems to show stock of configurable product. I have tried a lot of things that I found on Google, Stackoverflow, Magento Forums, but I failed. Here is the only solution that I cannot try:
$_product is your configurable product.
To get all its simple use :
$_product->getTypeInstance(true)->getUsedProducts ( null, $_product);
So you might have something like :
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null,
$_product) as $simple) {
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
echo $simple->getName()." with size ".$simple->getSize()." have a stock of $stock";
echo ''; } I let you adapt to your precise needs and ask question if needed
My problem is: I don't know where I can apply this solution!
()
You need to perform two step to get this working however I have checked this with version 1.8 but hope it will work in your case also
step 1. copy file app/code/core/mage/catalog/block/product/view/type/configurable.php
And create a folder under app/code/local with same directory structure mage/catalog/block/product/view/type/configurable.php
Now find function name getJsonConfig in configuration.php file.
Go to following code
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
);
Before this code place below two lines of code
$simpleproduct = Mage::getModel('catalog/product')->load($productsIndex);
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
Here you can see that i'm getting product stock by product id, now in info option array code you have to add one parameter
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
'qty' => $qty, // we are sending stock parameter so we can use it latter in drop down field
);
step 2. Now go js/varian/configuration.js
find the following line
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
Place following line under this
element.options[index].innerHTML += " Stock is :"+options[i].qty;
that's it all about cheer
Let me know if you have any query
with app/code/local/Mage/Catalog/Block/Product/View/Type/Configurable.php
$simpleproduct = Mage::getModel('catalog/product')->load($productsIndex);
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
'qty' => $qty, // we are sending stock parameter so we can use it latter in drop down field
);
$optionPrices[] = $configurablePrice;
}
}
and at js/varien/configurable.js
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
if (typeof options[i].price != 'undefined') {
element.options[index].setAttribute('price', options[i].price);
}
element.options[index].innerHTML += " Stock is :"+options[i].qty;
element.options[index].config = options[i];
index++;
}
isn't working at 1.9.4... is it something wrong?
I'm getting the below error while building taxonomy voccabulary and terms using the following code
FieldException: Attempt to create an instance of a field field_my_custom_vocab002 that doesn't exist or is currently inactive. in field_create_instance() (line 476 of C:\wamp\www\pur_theme\modules\field\field.crud.inc).
I checked the voccabulary and it is created, the problem is only with term creation
code
<?php
$new_vocab = (object) array(
'name' => 'My custom vocabulary002',
'description' => 'Test',
'machine_name' => 'my_custom_vocab002',
);
taxonomy_vocabulary_save($new_vocab);
$vocab = taxonomy_vocabulary_machine_name_load('my_custom_vocab002');
$term1 = (object) array(
'name' => 'Term 1',
'description' => 'This is term 1',
'vid' => $vocab->vid,
);
taxonomy_term_save($term1);
What/where did I wrong?
I think it's because you try to create a term with more fields than the 2 basical ones (name and vid). You have a "description" field in addition.
Try this code instead:
$term = new stdClass();
$term->name = 'Term 1';
$term->vid = $vocab->vid;
$term->field_description[LANGUAGE_NONE][0]['value'] = 'This is term 1';
taxonomy_term_save($term);
Source: http://www.lightrains.com/blog/programmatically-create-taxonomy-term-drupal
I found the only solution to this was to create the field it's looking for before creating the vocabulary. Personally I did this with a custom function:
function MY_MODULE_create_new_taxonomy($taxonomy_name, $taxonomy_machine_name, $taxonomy_description){
//Add field you know is going to cause trouble
$field = array(
'field_name' => 'field_'.$taxonomy_machine_name,
'type' => 'text',
'label' => 'Label'
);
field_create_field($field);
//create the vocab
$new_vocabulary = new stdClass();
$new_vocabulary->name = $taxonomy_name;
$new_vocabulary->machine_name = $taxonomy_machine_name;
$new_vocabulary->description = t($taxonomy_description);
$new_vocabulary->module = 'taxonomy';
taxonomy_vocabulary_save($new_vocabulary);
}
I'm working on a module where I need to save the records based on the scope of website and store. For that I need to have the select box as its in the system->configuration.
How can I get that select box in my form and save the website/store value in database so that it can be displayed in the specific store/website? Any suggestions on it?
Now I'm trying it breaking into two fields -> website and store. Now, how can I change the options in store based on the website selected?
Finally, I'd written my own code for this.
$scope = array('default' => 'default');
foreach (Mage::app()->getWebsites() as $website) {
$scope['website_' . $website->getCode()] = $website->getName();
foreach ($website->getGroups() as $group) {
$stores = array();
foreach ($group->getStores() as $store) {
$stores[] = array(
'label' => $store->getName(),
'value' => 'store_' . $store->getCode()
);
}
$scope[] = array(
'label' => $website->getName(),
'value' => $stores
);
}
}
$fieldset->addField('website', 'select', array(
'label' => Mage::helper('designer')->__('Website'),
'name' => 'website',
'values' => $scope
));
Thanks to this post by Marius