I want to insert several fields 'User detail' page NOT when registering, only for the back-end.
I added some codes in user-edit.php and I made a field named 'Company Name' but was NEVER saved!!!
Could you let me know what is wrong or is needed for saving it?
<tr class="user-company-name-wrap">
<th><label for="company_name"><?php _e( 'Company Name' ); ?></label></th>
<td><input type="text" name="company_name" id="company_name" value="<?php echo esc_attr( $profileuser->company_name ); ?>" class="regular-text" /></td>
</tr>
user-edit.php is a core file, and you should never add code to core files. Your code will be erased if any updates to Wordpress happen. I think this stack exchange post should help you add the functionality you want. I would suggest reading through all the answers to find which one would work best, and recommend using Advanced Custom Fields:
https://wordpress.stackexchange.com/questions/214719/how-do-i-add-a-field-on-the-users-profile-for-example-country-age-etc
Related
I am a total WooCommerce noob and I am struggling with something that I feel should be pretty simple...
How can I display specific "Additional Information" fields on a product page? I suppose I need to add some shortcode in the PHP files, but I am lost on what exactly to add...
I have ~15 additional info fields that I created under "Attributes" on the product.
I would like to display specific attributes on various parts of the page, but not all in one spot, much like the "Additional Fields" tab does.
I can't seem to find a straight answer and I am really struggling with this.
So, I realize there is a lack of information.
To further explain what I was trying to do, I was attempting to create a shortcode function in order to display specific "Attribute" fields from the woocommerce product.
In order to do this, I found a solution. This code can be added to your theme's function.php file:
// To diplay formula via shortcode within product page
add_shortcode( 'show_formula', 'show_additional_info_formula' );
function show_additional_info_formula() {
global $product;
$formula = $product->get_attribute('Formula');
?>
<table class="woocommerce-product-attributes shop_attributes">
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--formula">
<th class="woocommerce-product-attributes-item__label"><?php echo ucfirst( 'Formula' ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo $formula; ?></td>
</tr>
</table>
<?php
}
Then, the shortcode to use, is (in this instance), [show_formula].
You can modify this to match your desired outcome.
Change:
add_shortcode( 'show_your_info', 'show_additional_info_attribute_field' );
$your_field = $product->get_attribute('actual_woocommerce_field_name');
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--unique_name">
<th class="woocommerce-product-attributes-item__label"><?php echo ucfirst( 'word_to_be_displayed' ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo $your_field; ?></td>
Then, once modified, the shortcode you'd use:
[show_your_field]
This answer led me down the right path
Bit of an unusual customisation in WooCommerce that I require...
I've modified the standard WooCommerce cart.php so that the customer can't edit the quantity or remove items from cart. Basically, the customer first visits a seating plan page, selects their seat, and this then adds the relevant ticket (which is just a WC product) to their cart, and displays the cart page.
I want a column in the cart output, which has a button next to every row (every ticket) directing the customer back to the relevant seating plan for that ticket.
I've stored the seating plan shortcode in the WooCommerce product details, and I'm able to recall this in cart.php, and it displays in the right place as text using this line of code:
<td class="product-seating" data-title="<?php esc_attr_e( 'Seating Plan', 'woocommerce' ); ?>">
<?php echo the_field('wccaf_seating_plan_link', $product_id) ; ?>
</td>
This returns the following text nicely under a Seating Plan column in the cart for every ticket:
[tc_seat_chart id="3818" show_legend="true" button_title="Select your seat(s)" subtotal_title="Subtotal" cart_title="Continue to Checkout"]
However, what I actually want it to do is parse this shortcode, which should create a nice button with a link to the correct seating plan.
How would I make it parse the shortcode and not just display it as text? I tried playing around with do_shortcode but didn't have any luck.
Try this:
<td class="product-seating" data-title="<?php esc_attr_e( 'Seating Plan', 'woocommerce' ); ?>">
<?php $seating_plan = get_field('wccaf_seating_plan_link', $product_id) ;
echo do_shortcode($seating_plan);
?>
</td>
I am making user meta fields. I have to implement a field named business_profile and implement editor on it. I have implemented the editor but I can't seem to either save its value or retrieve it. Below is my code.
<tr>
<th>
<label for="address">Business Profile</label></th>
<td><?php
$content = get_the_author_meta('business_profile', $user->ID);
$editor_id = 'mycustomeditor';
wp_editor($content, $editor_id);
?>
</td>
</tr>
And for update:
update_usermeta($user_id, 'business_profile', $_POST['business_profile']);
Where am I wrong?
Your code should read
update_usermeta($user_id, 'business_profile', $_POST['mycustomeditor']);
since mycustomeditor is the $editor_id than this is how the $_POST variable would be named .
business_profile on the other hand is just the meta_data for user or user_meta name .
It appears you just confused the two .
I am trying to create a separate menu section on wordpress admin panel which will contain three pages. The pages will behave exactly like the normal wordpress pages, I just want to have a separate menu section in the admin panel. I am able to use wp_editor() to display the editor within a form. My problem is how do I get the content from the editor and how do save into the wp_post in the database? Here is the piece of code I have already come up with:
<?php
$content = '';
wp_editor('test', 'mydescription', array('textarea_name' => 'my_description', 'tinymce' => true));
?>
<p><div class="submit"><input type="submit" name="save_front_content_options" value="<?php _e('Save Changes', 'save_options') ?>" style="font-weight:bold;" /></div></p>
<input type="hidden" name="action" value="save" />
</form>
If I understand correctly, you are looking for the Settings API:
Settings API tutorial.
Settings API documentation.
I need to create a wordpress plugin to connect wordpress to a central login. But all I want is the user to be able to post comments with name and email filled. I don't think I need create a real loggin into wordpress because the user should not be able to write posts or do admin stuff. I want him only to post comments.
I search the documentation but could not find any action for comments.
How can I change the html of a comment form?
Maybe not good but it works...
Fill comment author and email from central login stored in session:
function portal_user_comment()
{
$_POST['author'] = $_SESSION['portal']['name'];
$_POST['email'] = $_SESSION['portal']['email'];
}
add_action('pre_comment_on_post', 'portal_user_comment');
Edit comments.php from the template. Look for:
<input type="text" name="author" id="author" value="<?php $comment_author; ?>" ...>
<input type="text" name="email" id="email" value="<?php $comment_author_email; ?>" ...>
Set both fields disabled="true" and replace the values with the author and email from the session.