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']
Related
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
We need to have two tables in review-order.php to display Invoiced items in Table 1 and Credit Card Purchases in Table 2.
Here I have a basic overview of the concept.
<?php if($gateways == 'bacs') { ?>
<div id="order_review">
<table class="shop_table">
<thead>
<tr>
<th class="product-name"><?php _e('Invoice Products', 'yit'); ?></th>
<th class="product-quantity"><?php _e('Qty', 'yit'); ?></th>
<th class="product-total"><?php _e('Totals', 'yit'); ?></th>
</tr>
</thead>
TABLE 2
<?php if($gateways == 'paypal') { ?>
<div id="order_review">
<table class="shop_table">
<thead>
<tr>
<th class="product-name"><?php _e('Credit Card Products', 'yit'); ?></th>
<th class="product-quantity"><?php _e('Qty', 'yit'); ?></th>
<th class="product-total"><?php _e('Totals', 'yit'); ?></th>
</tr>
</thead>
The problem is that the tables disappear completely when wrapped within an IF.
If anyone could help with at least some better ideas that would be much appreciated. THANKS!
Where are you getting the $gateways variable from? Without knowing, it is hard to see why your code doesn't work. But here is the code to get the gateways.
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
foreach ( $available_gateways as $gateway ) {
if ( $gateway->chosen === 'paypal' ) {
// do something
}
// alternative you can try id if that matches
if ( $gateway->id === 'paypal' ) {
// do something
}
}
when i install this wordpress plugin it gives me:
The plugin generated 189 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
this is my code:
add_action('wp_head', 'wpse_43672_wp_head', 0);
/**
* Hooks into the `wp_head` action.
*/
function wpse_43672_wp_head(){ ?>
<script>
if (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/) ||
navigator.userAgent.match(/Windows Phone/i) ||
navigator.userAgent.match(/ZuneWP7/i)
) {
// some code
self.location="<?php echo plugins_url(); ?>/zeevmobile/mobile-page.php";
}
</script>
<?php }?>
<style>
li#toplevel_page_zeevmobile-zeevmobile .wp-menu-image {
background: url(<?php echo plugins_url(); ?>/zeevmobile/images/icon.png) no-repeat 4px !important;
}
</style>
<?php
// create custom plugin settings menu
add_action('admin_menu', 'zeev_create_menu');
function zeev_create_menu() {
//create new top-level menu
add_menu_page('zeev movile redirect', 'zeev mobile', 'administrator', __FILE__, 'zeev_settings_page');
//create new top-level menu
//call register settings function
add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
//register our settings
register_setting( 'zeev-settings-group', 'zeev_above_text' );
register_setting( 'zeev-settings-group', 'zeev_normal_site' );
register_setting( 'zeev-settings-group', 'zeev_mobile_site' );
}
function zeev_settings_page() {
?>
<div class="wrap">
<h2>Your Mobile Buttons Links</h2>
<form method="post" action="options.php">
<?php settings_fields('zeev-settings-group'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Some text above buttons</th>
<td><textarea name="zeev_above_text" cols="90"><?php echo get_option('zeev_above_text'); ?></textarea></td>
</tr>
<tr valign="top">
<th scope="row">Normal Site Link</th>
<td><textarea name="zeev_normal_site" cols="90"><?php echo get_option('zeev_normal_site'); ?></textarea></td>
</tr>
<tr valign="top">
<th scope="row">Mobile Site Link</th>
<td><textarea name="zeev_mobile_site" cols="90"><?php echo get_option('zeev_mobile_site'); ?></textarea></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php }?>
i know that the "unexpected output" problem is coming from this file because when i delete all the php in it i don't get the problem.
can you please help me fix it ?
i uploaded it here:
http://zeevm.co.il/zeev-mobile-new.zip
Per comments, the error message is basically WP complaining that something is getting echoed when the file is included.
From a cursory glance at your code, it looks like your <style> tag is getting echoed -- it's not scoped within a function. There might be other similar issues elsewhere in the plugin.
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 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!