Woocommerce My Account Order page overriding is not working [duplicate] - wordpress

I want to style the content of some order columns in the list of orders (My Account area).
The problem is, that every content starts without any elements which I could use for styling.
For example: I want to give the order status a background color like a badge.
At the moment the status is the only content in the column. Like this:
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status" data-title="Status">
Completed
</td>
I want to change it to this:
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status" data-title="Status">
<span class="badge badge-success">Completed</span>
</td>
The class is an option. I could also style the simple <span> based on he class of the <td>.
Is there any way to change the output of the columns without touching the template file?
It's a very crucial template and I don't want to change it for such a simple addition.
In the template I saw this action before the content of each column:
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
Is there a way to use it?

That is indeed the correct way, use the column id 'order-status' in this case
woocommerce_my_account_my_orders_column_{$column_id}
function my_callback( $order ) {
echo '<span class="badge badge-success">' . esc_html( wc_get_order_status_name( $order->get_status() ) ) . '</span>';
}
add_action( 'woocommerce_my_account_my_orders_column_order-status', 'my_callback', 10, 1 );

Related

I can't debug whats wrong with my ACF get_field() to display an image array's url value

So my code is pretty straightforward. I am just getting a field value from the global fields (Options). So this field is on Dashboard -> Options (I have ACFpro) and I am trying to echo out a logo which is an image array.
This is how my code looks like
<ul class="text-white p-0">
<a class="brand " href="/">
<?php
$image = get_field('logo');
echo '<p id="debug">'.($image ['url']).'</p>';
?>
</a>
</ul>
al i am trying to do is pull the url value and insert it to a <p> tag just to make sure it pulls the right value. but instead I am getting this error.
error when trying to echo $image
Any idea on what am I doing wrong?
It is one of two things. You need to add the ID or options to the get_field() as a parameter or you need to adjust the return format. By default it tries to pull the ID of the page get_field() is on.
I would change it to
get_field( 'logo', 'options' );
Or change options to whatever you called your options page.
https://www.advancedcustomfields.com/add-ons/options-page/

WooCommerce how to display specific "Additional Information" fields

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

How to wrap HTML/PHP concatenation in Wordpress Function

I'm making my first basic Wordpress Theme, and trying to create a function to retrieve and display the first 6 posts, which I could use in various areas depending on the page you're on. It is very similar to this tutorial, that I found... after facing the fact it doesn't work in my theme.
Here is a simplified piece of the code (I tried several versions) :
function show_last_items() {
while ( have_posts() && $count < 6) :
the_post();
$count++;
print '<article id="post-'.the_ID().'" class="post-link-display">
<a href="'.the_permalink().'" title="'.the_title_attribute().'">
<div class="date">
<p>'.the_time( 'd/m' ).'</p>
</div>
<div class="title">
<h6>'.the_title().'</h6>
</div>
</a>
</article>';
endwhile;
}
For some reason, while the code inside the function works just fine if I use it directly on a template part (for example sidebar.php), all the HTML seems to be wiped off when used as a function... Or more exactly, it still exists, but in-between the data. So I get something like this displayed :
55http://localhost/myTheme/posts/55/my-post-title/My post title19/03My
post title
56http://localhost/myTheme/posts/56/my-other-post-title/My other post
title19/03My other post title
Yet the <article> tag and every markup in it is still there, empty, after each line that displays the retrieved information. I'd really like to understand why the concatenation doesn't work properly in this case. Is it something about the theme support ? It doesn't seem to me the WP_Widget class would change anything to this issue, but maybe I'm wrong ?
Try this
function show_last_items() {
while ( have_posts() && $count < 6) :
the_post();
$count++;
sprintf('<article id="post-%s" class="post-link-display">
<a href="%s" title="%s">
<div class="date">
<p>%s</p>
</div>
<div class="title">
<h6>%s</h6>
</div>
</a>
</article>', the_ID(), the_permalink(), the_title_attribute(), the_time( 'd/m' ), the_title());
}
Have you tried building a string and then returning it?
$return_string = '';
// while loop
$return_string .= '<article .....';
// end while
return $return_string;

Woocommerce Cart - parsing shortcode within cart output

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>

Why need "display:none" here in the code?

<div class="row">
<div class="large-12 columns">
<div class="row collapse featured-option">
<input id="featured" name="featured" type="checkbox" style="display: none;" <?php echo esc_attr( $featured_disabled ); ?>>
<span class="custom checkbox <?php echo esc_attr( $featured_disabled ); ?>"></span> <?php echo sprintf( __( 'Feature Proposal %s', APP_TD ), sprintf( _n( '(1 credit)', '(%d credits)', hrb_required_credits_to('feature_proposal'), APP_TD ), hrb_required_credits_to('feature_proposal') ) ); ?>
</div>
</div>
</div>
I'm trying to edit this wordpress theme code to use it for my own website.
But I don't know why style="display: none;" is needed here.
When I erase this style element, I get checkbox on the screen
but the functions are not working as it should be.
What's wrong with this? Why need "display: none"?
Please help
In this instance it is simply just hiding the checkbox. When
style = "display:none;"
is used, the page will be displayed as if the item does not exist. Meaning the layout of the page will not show a "hole" or something where that item is missing. In other words, the layout will not be affected by this.
The other way to hide something would be with,
style = "visibility:hidden;"
However, the page layout will be affected and the hidden item will still take up the same space.
Depending on what was trying to be accomplished, the checkbox could be hidden for different reasons. It's possible that the programmer of this code wanted to hide this checkbox by default and then show it later on after certain events occurred. Additionally, there are times when it is best to show and hide objects as you need them or don't need them rather than constantly recreating or deleting them.

Resources