Retrieving data from customer area wordpress - wordpress

I'm trying to put on bold the title from some post on wordpress, I have this piece of code for it:
<?php
$title_popup = sprintf(__('Uploaded on %s', 'cuar'), get_the_date());
$file_count = cuar_get_the_attached_file_count($post->ID);
if(strpos(get_the_title(get_the_ID()),'Garajes Gran')!==false){
?>
<tr>
<td class="cuar-title">
<strong><?php the_title(); ?></strong>
</td>
<td class="text-right cuar-file-count">
<span class="label label-rounded label-default"><?php echo sprintf(_n('%1$s file', '%1$s files', $file_count, 'cuar'), $file_count); ?> </span>
</td>
</tr>
<?php
}
And I don't get what I want because all titles appears on black.So what is wrong?. The titles which I have are:
Presupuestos (Garajes Gran Via) 0 files
Presupuestos (Viviendas) 0 files
Contratos (Garajes Gran Via) 5 files
Contratos (Viviendas Gran Vía) 6 files
Contadores de Agua 0 files
Estatutos (Viviendas) 1 file
Estatutos (Garajes Gran Vía)
Thanks so much.

Instead of using the_title(); use get_the_title();
<td class="cuar-title">
<strong><?php echo get_the_title(); ?></strong>
</td>

Related

Customize WooCommerce My Account>Downloads table to display downloadable file links in a single row

I'm attempting to override WooCommerce>Templates>downloads.php to display a custom table that shows the links for multiple downloadable file types in a single row.
My current code is as follows:
'''
<?php
$downloads = WC()->customer->get_downloadable_products();
$has_downloads = (bool) $downloads;
<?php do_action( 'woocommerce_before_account_downloads', $has_downloads ); ?>
<table>
<thead>
<tr>
<th>Title</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<tr>
<td>
<a class="productLink" href="<?php echo get_permalink( $loop->post->ID ) ?>">
<?php the_title(); ?>
</a>
</td>
<td>
/*This is the bit that doesn't work*/
<?php
$files = $product->get_downloads();
foreach( $files as $key => $each_download ) {
echo 'File Name | ';
}
?>
</td>
</tr>
<?php endwhile; wp_reset_query(); // Remember to reset ?>
</tbody>
</table>
'''
I'm struggling with how to show the downloadable file links with the filenames visible and separated by a vertical line | .

Change WooCommerce attribute table to two columns

I'm very new to Wordpress/WooCommerce and I'm trying to do something I thought would have been simple.
The very basic WooCommerce Single Product page has the Product Attributes, they all appear under one big column.
Where can I actually modify the style and css for Product Page, so that I can have them in 2 columns?
I see the table is itself is generated under class "woocommerce-product-attributes" and "shop_attributes" ?
Any guidance is very appreciated.
Had the same issue, solved it by editing woocommerce/templates/single-product/product-attributes.php. To make the change permanent between woocommerce updates, copy the file contents to yourtheme/woocommerce/single-product/product-attributes.php.
Change:
<table class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
</tr>
<?php endforeach; ?>
</table>
to:
<table>
<?php foreach (array_chunk($product_attributes, 2) as $product_attribute_key => $product_attribute) :{ ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<?php foreach ($product_attribute as $value) :{ ?>
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $value['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $value['value'] ); ?></td>
<?php } endforeach; ?>
</tr>
<?php } endforeach; ?>
</table>

Editing the invoice template in Woocommerce

I need to edit the Woocommerce invoice template with coding. I Copied all the files from wp-content/plugins/woocommerce-pdf-invoices-packing-slips/templates/Simple to to my child them in wp-content/themes/church-event-child/woocommerce/pdf/yourtemplate and customized them there. I need the template like this:
Subtotal: € 0
IVA: € 0
Order total: € 0
But woocommerce simple template only shows it like this
Subtotal: € 0
Order total: € 0
So it is about adding the IVA with the amount inside. Here you can see the code I am trying to change, but I dont know how to find where the label of the tax_amount is kept and how to display it right.
<table class="totals">
<tfoot>
<?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
<tr class="<?php echo $key; ?>">
<td class="no-borders"></td>
<th class="description"><?php echo $total['label']; ?></th>
<td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
</tr>
<?php endforeach; ?>
</tfoot>
</table>
Thanks in Advance

Manage custom posttype function using an additional menu in dashboard

I have created a child theme for twenty-seventeen in wordpress and created a slider function to display slider images and also a custom post type for the function.
Now I created an extra menu under appearances in dashboard as Slider settings and I need to manage the slider using that settings.
In that settings I need to have the following
o Enable slider option (check box)
o Enable slider only for logged in users (check box)
o Set a global title for slider block (text field)
I Added in back end but no condition added in front end to display slides based on this.
How could I do this?
You can use this code and change page for rendering options:
<?php
add_action('admin_menu', 'create_menu');
function create_menu() {
add_options_page(__( 'Plugin Settings', 'textdomain' ),__( 'Plugin Settings', 'textdomain' ), 'administrator', __FILE__, 'settings_page', __FILE__);
add_action( 'admin_init', 'mysettings' );
}
function mysettings() {
register_setting( 'settings-group', 'enable_slider' );
register_setting( 'settings-group', 'enable_slider_loggedin' );
register_setting( 'settings-group', 'slider_title' );
}
function settings_page() {
?>
<div class="wrap">
<h2><?php _e('PluginSettings','textdomain'); ?></h2>
<form method="post" action="options.php">
<?php settings_fields( 'settings-group' ); ?>
<?php do_settings_sections( 'settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e(' Enable slider','textdomain'); ?></th>
<td>
<input name="enable_slider" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider' ) ); ?> />
<p class="description"></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Enable slider only for logged in users','textdomain'); ?></th>
<td>
<input name="enable_slider_loggedin" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider_loggedin' ) ); ?> />
<p class="description"></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Title For Slider','textdomain'); ?></th>
<td><input type="text" name="slider_title" value="<?php echo get_option('slider_title'); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
Using like this:
if ( get_option ('enable_slider') == 1 ) {
// enable
} else {
//disable
}

WordPress logs out after using /wp-admin/admin.php

i'm currently updating a system with a new function. I'm adding the show_user_profile and edit_user_profile action to add custom data into the user-view:
<script type="text/javascript">
function bindRemoveButton() {
jQuery(function($) {
$('table.available-users button.remove').on('click', function() {
$(this).parent().parent().remove();
});
});
}
bindRemoveButton();
</script>
<table class="form-table available-users">
<tbody>
<tr>
<th>
<label for="accounts"><?php print __('Assigned accounts', ZVA_I18N); ?></label>
<br />
<br />
<a href="<?php bloginfo('template_directory'); ?>/templates/admin/user_add_box.php#TB_iframe=true&width=600&height=550" title="<?php print __('Add User', ZVA_I18N); ?>" class="thickbox button button-primary"><?php print __('Add', ZVA_I18N); ?></button>
</th>
<td>
<table class="wp-list-table widefat fixed users">
<thead>
<tr>
<th scope="col" class="manage-colum" style="padding-left: 20px;"><span><?php print __('Username', ZVA_I18N); ?></span></th>
<th scope="col" class="manage-colum"><span><?php print __('Date From', ZVA_I18N); ?></span></th>
<th scope="col" class="manage-colum"><span><?php print __('Date To', ZVA_I18N); ?></span></th>
<th scope="col" class="manage-colum"><span><?php print __('Action', ZVA_I18N); ?></span></th>
</tr>
</thead>
<tbody>
<?php
foreach($user_available AS $aindex => $available_user) {
$user = new WP_User($available_user['user_id']);
?>
<tr>
<td><?php print $user->user_login; ?> (<?php print $user->display_name; ?>)</td>
<td>
<input type="text" name="jumper_day_from[<?php print $user->ID; ?>]" size="2" value="<?php print date('d', $available_user['from']); ?>" placeholder="DD" />.
<input type="text" name="jumper_month_from[<?php print $user->ID; ?>]" size="2" value="<?php print date('m', $available_user['from']); ?>" placeholder="MM" />.
<input type="text" name="jumper_year_from[<?php print $user->ID; ?>]" size="4" value="<?php print date('Y', $available_user['from']); ?>" placeholder="YYYY" />
</td>
<td>
<input type="text" name="jumper_day_to[<?php print $user->ID; ?>]" size="2" value="<?php print date('d', $available_user['to']); ?>" placeholder="DD" />.
<input type="text" name="jumper_month_to[<?php print $user->ID; ?>]" size="2" value="<?php print date('m', $available_user['to']); ?>" placeholder="MM" />.
<input type="text" name="jumper_year_to[<?php print $user->ID; ?>]" size="4" value="<?php print date('Y', $available_user['to']); ?>" placeholder="YYYY" />
</td>
<td>
<button type="button" class="remove button button-primary"><?php print __('Remove', ZVA_I18N); ?></button>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
Okay, no problems. See the Line 19 on my code, here i add a Link/Button to open a new Thickbox with additional content. When i click on the link, a thickbox pops up and displays the content from the File /wp-content/themes/MyTheme/templates/admin/user_add_box.php.
To use WordPress's own functions (like $wpdb or other), im including the admin.php on the user_add_box.php - YES, currently that's only these line on the file:
<?php
define('WP_ADMIN', true);
/* Nativate to /wp-admin/ directory */
require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/wp-admin/admin.php');
?>
When i'm open the tickbox, the login will be shown - curiously. After that i'm complete logged out from WordPress.
I work very very long with WordPress and never had such problems. Especially since I also developing for years themes and plugins for WordPress.
Can you tell me, what i'm doing wrong? Why the system logs me out?
Thanks for your help.
EDIT
After see the core file, i see i must define constants like define('WP_ADMIN', true);, but thats dont solve the problem.
In the auth_redirect method (wp-includes/pluggable.php) will be checked if the file comes from wp-admin directory:
if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') )
If not, the system will be redirect automatical to the wp-login.php.
Solve it to rewrite the $_SERVER['REQUEST_URI'] variable:
<?php
$_SERVER['REQUEST_URI'] = 'wp-admin';
require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/wp-admin/admin.php');
?>
Otherwise, add only wp-load.php and wp-admin/includes/admin.php:
<?php
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REFERER'];
require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/wp-load.php');
require_once(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . '/wp-admin/includes/admin.php');
?>

Resources