I have created a menu to manage user records for wordpress admin. While listing the record I have used check box to select and unselect the record as in Pages menu.
I have to select whole address or name on checkbox click. But here what happens is that when I click on name it selects whole checkbox including name and address. I do not have an idea how the check box works.
Here is the code
<?php
foreach($record as $record_row)
{
$name = $record_row->name;
$address = $record_row->name;
?>
<tr>
<th class="check-column" scope="row">
<input name="names[]" class="one" type="checkbox" value="<?php echo $record_row->ID; ?>">
</th>
<th class="check-column" scope="row">
<input name="address[]" class="two" type="checkbox" id="address[]" value="<?php echo $record_row->ID; ?>">
</th>
<td class="column-icon media-icon" width="30%"><?php echo $record_row->name; ?></td>
<td class="post-title page-title column-title"><?php echo $record_row->name; ?></td>
</tr>
<?php
}?>
Can anyone help me. Thanks in advance.
Get rid of the id attribute on the checkbox - it's invalid syntax for starters, and every id in your document must be unique!
Related
I have been able to find a way to add a custom field to a Woocommerce Product Vendor's "Edit Vendor" screen, that the Admin (me) can edit - using the following code. But, the vendor has NO access to this same custom field, and the custom field doesn't show up in their public profile.
To clarify, my goal is to add a custom field to a Woocommerce Product Vendor's public profile that can be edited by the vendor.
Thanks!
add_action('wcpv_product_vendors_edit_form_fields', 'edit_vendor_custom_fields', 10);
function edit_vendor_custom_fields($term) {
$vendor_data = get_term_meta( $term->term_id, 'vendor_data', true );
$custom_field = isset( $vendor_data['custom_field'] ) ? $vendor_data['custom_field'] : '';
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="custom_field">test</label></th>
<td>
<input type="text" name="vendor_data[custom_field]" id="custom_field" value="<?php echo esc_attr($custom_field); ?>" />
</td>
</tr>
<?php
}
We are preparing a template for factory QC. The template is automatically filled with all the order information and it will then be printed for their use.
This is a part of the template where the order meta items are listed, whenever we try to get the order items we get all details, we need to extract them each one by one
<table width="100%" border="0" cellpadding="7" cellspacing="0" style="text-transform: uppercase; font-size: 12px;">
<?php foreach ( $this->get_order_items() as $item_id => $item ) ?>
<tr>
<td width="35%">
Order No:
</td>
<td width="65%" style="font-weight: bold; ">
#F1-<?php $this->order_number(); ?>
</td>
</tr>
<tr>
<td>
Model:
</td>
<td style="font-weight: bold; ">
<?php echo $item['meta']; ?> //order items
</td>
</tr>
<tr>
<td>
Design:
</td>
<td style="font-weight: bold; ">
<?php echo $item['name']; ?> // product name
</td>
</tr>
</table>
The $item['meta'] gives us the following
MODEL: A4
YEAR: 2022
MAKE: Audi
COLOR: BLACK
LINE COLOR: ORANGE
We only need the model for the model row, we will put the color information and year in another table lets say. How can we extract the model in this case
<?php $item_meta = $item['meta']; ?>
<?php foreach ($item_meta as $meta_id => $meta) ?>
<?php echo $meta['Model']; ?>
We tried to use this to go through the elements one by one and get the value by meta key but it is always empty.
Edit:
We were able to get the value for Model using
wc_get_order_item_meta( $item['item_id'], 'Model' );
You just need to put the 2-d array structure there as you can access the model from the items just like that.
$item['meta']['Model']
I'm sorry if this is an old question but I really can't find answer for this. I am new to wordpress plugin development. How can I do a somewhat like a callback before a form is submitted using WP Options API? In a native PHP, we can just say as
if (isset($_POST['submit'])) {
$options = $_POST['zt_ftp_settings'];
var_dump($options);
}
However, I am using the WP Options API. It saves the data correctly, I just want to do some more after saving the data.
Here is what I did,
<form method="post" action="options.php">
<?php
settings_fields('zt_ftp_settings_options' );
do_settings_sections( 'zt_ftp_settings_options' );
$option = get_option('zt_ftp_settings');
?>
<h2>FTP Settings</h2>
<p>Please provide your ftp credentials.</p>
<table class="form-table">
<tbody>
<tr>
<th scope="row">FTP Hostname</th>
<td>
<input name="zt_ftp_settings[zt_ftp_host_name]" type="text" id="zt_ftp_host_name" value="<?php echo $option['zt_ftp_host_name']?>" class="regular-text">
</td>
</tr>
<tr>
<th scope="row">FTP Username</th>
<td>
<input name="zt_ftp_settings[zt_ftp_user_name]" type="text" id="zt_ftp_user_name" value="<?php echo $option['zt_ftp_user_name']?>" class="regular-text">
</td>
</tr>
<tr>
<th scope="row">FTP Password</th>
<td>
<input name="zt_ftp_settings[zt_ftp_password]" type="password" id="zt_ftp_password" value="<?php echo $option['zt_ftp_password']?>" class="regular-text">
</td>
</tr>
</tbody>
</table>
<?php submit_button( 'Save Settings' ); ?>
Thanks.
Use WP AJAX functionality.
Use below JS,
$("#submit").click(function(){
var url = window.location.href;
jQuery.post(
ajaxurl,
{
'action': 'delete_search',
'tid': tid,
},
function(response){
location.reload();
});
});
Replace your submit button ID and use your form values.
Use below code in function.php
function prefix_ajax_delete_search() {
global $wpdb;
$user_id = get_current_user_id();
$wpdb->delete('sf_save_search', array('id' => $_POST['tid']) );
wp_die();
}
add_action( 'wp_ajax_delete_search', 'prefix_ajax_delete_search' );
As per your requirement change the function name and variables
i have built several diffrent templates for my WP site each calling diffrent metas.
ok, im looking for a way to add a meta-box that will only display if the correct page template is selected.
say i have a homepage.php template, this template calls some specific meta info that only the homepage uses, a call to action of example, so i need the meta-box to appear once the proper page template is selected and disappear if a different page template is selected.
any help is appreciated.
get_page_template will return the template you are looking at. You can switch on this to display the content you want.
ok i finally found a way around it guys and here it is:
<?php
function my_admin() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
// check for a template type
if ($template_file == 'home.php'){
add_meta_box( 'product_info',
'Informacion de Producto',
'display_product_info_meta_box',
'ex_producto', 'normal', 'high'
);
}
}
function display_product_info_meta_box( $product_info ) {
$product_price = floatval( get_post_meta( $product_info->ID, 'product_price', true ) );
$product_code = esc_html( get_post_meta( $product_info->ID, 'product_code', true ) );
?>
<table>
<tr style="width: 100%">
<td >Precio Producto</td>
<td><input type="text" size="80" name="product_info_product_price" value="<?php echo $product_price; ?>" /></td>
</tr>
<tr style="width: 100%">
<td >Codigo de Producto</td>
<td><input type="text" size="80" name="product_info_product_code" value="<?php echo $product_code; ?>" /></td>
</tr>
</table>
<?php
}
add_action( 'admin_init', 'my_admin' );
?>
so... yeap i hope that dose someone out there some good :)
I have the following code:
<?php
echo $form->create('User', array('url' => array('controller' => 'users', 'action' =>'login')));
echo $form->input('User.username');
echo $form->input('User.password');
echo $form->end('Login');
?>
and that creates a form that looks similar to this:
username
[TextBox]
password
[TextBox]
and I want it to look like this:
username [TextBox] password [TextBox]
Is there an option or something I can use to do this?
Either float the elements next to each other, or display them inline. I normally only use floats when they're absolutely necessary - inline elements are much simpler to work with anyway.
<form method="post" action="">
<fieldset>
<dl>
<dt><label for="username">Username:</label></dt><dd><input type="text" name="username" value="Username" id="username" /></dd>
<dt><label for="password">Password:</label></dt><dd><input type="password" name="password" id="password" /></dd>
</dl>
</fieldset>
</form>
Essentially all you need to add is either inline-block or inline to your list elements:
dt { display: inline; }
dd { display: inline; }
Preview: http://jsfiddle.net/Wexcode/Wav9B/
After I had struggled with css-styles I end up using tables like this:
<?php
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' =>'login'))); ?>
<table>
<tr>
<td><?php echo $this->Form->input('User.username'); ?></td>
<td><?php echo $this->Form->input('User.password'); ?></td>
<td><?php echo $this->Form->button('Submit Form', array('type'=>'submit')); ?></td>
</tr>
</table>
<?php echo $this->Form->end(); //This and "create" has to be outside <table> to pass xhtml validation ?>
Wrap all fields in one div. Float everything to the left, setting appropriate right margins. Clear the div.