what is the method for add a column in the admin order list with a simple sequential number?
Just add a column with 1 / 2 / 3 / 4 for the single order, just for have a quick view about the number of order with a filter active.
I try with a plugin but I think I need to modify the WooCommerce file of the theme.
The order_id in WooCommerce is the id in wp_posts table which is used for many things, posts, pages, orders ... That's why the order ids are rarely in sequence.
This means you have to add a separate sequence and keep track of it.
There is a plugin that does exactly that:
https://wordpress.org/plugins/wt-woocommerce-sequential-order-numbers/
You can configure it to use a numbered sequence or any other custom sequence.
The plugin is storing data into "_order_number" postmeta and replaces the original first column content, like this
enter image description here
If you want to see this sequence number in a separate column then you can use a plugin like: https://wordpress.org/plugins/codepress-admin-columns/
to add a custom column with the order number
enter image description here
EDIT: Adding code snippet to show sequential numbers in the first column.
function custom_columns_head_only_shop_order( $columns ) {
$new_columns = array( 'sequential_number' => 'Sequential Number' );
$columns = array_merge( $new_columns, $columns );
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'custom_columns_head_only_shop_order', 10 );
function custom_columns_content_only_shop_order( $column_name ) {
if ( $column_name == 'sequential_number' ) {
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$per_page = get_query_var( 'posts_per_page' );
$offset = ( $paged - 1 ) * $per_page;
global $sequential_number_counter;
if ( ! isset( $sequential_number_counter ) ) {
$sequential_number_counter = 0;
}
$sequential_number_counter++;
echo $offset + $sequential_number_counter;
}
}
add_action( 'manage_shop_order_posts_custom_column', 'custom_columns_content_only_shop_order', 10, 1 );
Related
Referring to the answer found here - Customize total rows from WooCommerce order table
I would like to change the items order in Order details table on the /checkout/order-received/ page and in email that the customer receives
I have added an extra line in the Order details table "Total excl. VAT:" which I got from this code
add_filter( 'woocommerce_get_order_item_totals', 'add_order_total_excl_vat_row', 10, 3 );
function add_order_total_excl_vat_row( $total_rows, $order, $tax_display ) {
// Only on emails notifications
if( ! is_wc_endpoint_url() || ! is_admin() ) {
// Set last total row in a variable and remove it.
$gran_total = $total_rows['order_total'];
unset( $total_rows['order_total'] );
// Insert our new row
$total_rows['order_total_ev'] = array(
'label' => __( 'Total excl. VAT: ', 'woocommerce' ),
'value' => wc_price( $order->get_total() - $order->get_total_tax() ),
);
// Set back last total row
$total_rows['order_total'] = $gran_total;
}
return $total_rows;
}
I have managed to rearrange the order of the items in the Order details table with this code:
add_filter( 'woocommerce_get_order_item_totals', 'reordering_order_item_totals', 10, 3 );
function reordering_order_item_totals( $total_rows, $order, $tax_display = '' ){
$sorted_items_end = array('order_total_ev', 'order_total', 'payment_method');
$sorted_total_rows = array(); // Initializing
// Loop through sorted totals item keys
foreach( $sorted_items_end as $item_key ) {
if( isset($total_rows[$item_key]) ) {
$sorted_total_rows[$item_key] = $total_rows[$item_key]; // Save sorted data in a new array
unset($total_rows[$item_key]); // Remove sorted data from default array
}
}
return array_merge( $total_rows, $sorted_total_rows); // merge arrays
}
What I want to achieve is to add Tax value after the 'order_total_ev' (Price excl. VAT) and before 'order_total'
My PHP knowledge is very limited and I appreciate any help.
I am trying to get variations of a variable product on custom product page. I have two attributes, one for sizes as select and the other for colors as swatches. The problem that I cannot display the attribute that I need to display, and when I use the following code it returns a text names of sizes or colors not the select dropdown for sizes or the colors swatches. Any help please ?!
echo implode(', ', wc_get_product_terms( $product_id, 'pa_colors' ));
This is a brief code to solve your question, I let you entire code, you can use only that you need.
The first is check if get_product function exists, and check the product type, to create a correct product object with the id (in my case $idProduct).
It work on woocommerce 3.x, I don't test it on woocommerce < 3.x.
if( function_exists('get_product') ) {
$product = get_product( $idProduct );
if ( $product->is_type( 'variable' ) ) {
$product = new WC_Product_Variable( $idProduct );
$available_variations = $product->get_available_variations(); //get all child variations
$variation_variations = $product- >get_variation_attributes(); // get all attributes by variations
// taxonomy => terms
// pa_attribute-color => array('blue', 'red', green)
// Use ex: get_taxonomy('pa_attribute-color')->labels; to get the Name and not the slug to attributes, it can be the taxonomy
// Use ex: get_term_by('name', 'pa_attribute-color', 'pa_attribute-color); to get the Name/label
$result = array( $available_variations , $attributes); // only to see the result you can use var_dump, error_log, etc.
//...
//...
}elseif ( $product->is_type( 'bundle' ) && class_exists( 'WC_Product_Bundle' ) ) {
$product = new WC_Product_Bundle( $idProduct );
}else{
$product = new WC_Product( $idProduct );
}
}
Also you try with:
$product->get_attribute( $key );
wc_attribute_label($key);
where $key can be pa_color , pa_size, etc
I hope help you.
I currently have a page that displays only 1 post because I wanted to have 1 post per day and that show up on the homage.
I have decided to have multiple posts in a day but I only want the homepage to display posts from the current day only.
What in my loop could I change to accomplish this?
My site is http://thatshitsawesome.com for reference.
Firstly you must increase the number of visible posts shown at most. I assume you know how to do this already as you've managed to limit it to one per query. For completion you can change it using the posts_per_page condition in the query arguments or in the "Blog pages show at most" value set under settings in the admin panel if you want to use the default value.
To limit posts to the current day use some specific Time parameters as defined in the WP_Query reference. You need the conditions year, monthnum and day.
Example:
<?php
// Limit query posts to the current day
$args = array(
'year' => (int) date( 'Y' ),
'monthnum' => (int) date( 'n' ),
'day' => (int) date( 'j' ),
);
$query = new WP_Query( $args );
// The Loop
while ( $query->have_posts() ) :
$query->the_post();
// ...
endwhile;
?>
If you're not using an explicit query but rely on the internal WP Query a common way to change the internal query is using the pre_get_posts action. Add the function below to your functions.php file to only show posts from the current day and only on the frontpage.
Example:
<?php
function limit_posts_to_current_day( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'year', (int) date( 'Y' ) );
$query->set( 'monthnum', (int) date( 'n' ) );
$query->set( 'day', (int) date( 'j' ) );
}
}
add_action( 'pre_get_posts', 'limit_posts_to_current_day' );
?>
Is there a way to exclude a post from all of Wordpress' RSS feeds (the default one as well as tags, categories, and search feeds)?
Assuming you do not want to use plugins like THIS ONE or THIS, you have many ways :
One is to assign a category for the posts you would like to exclude and then you can just change the URL of the RSS link like so :
http://www.mydomain.com/feed?cat=-x,-y,-z
You can also FILTER with a function :
function o99_my_rss_filter($query) {
if ($query->is_feed) {
$query->set('cat','-7'); //Put category ID - here it is : 7
}
return $query;
}
add_filter('pre_get_posts','o99_my_rss_filter');
The point is that you will need to assign SOMETHING (tag, custom field, category) to identify what to exclude , assuming that you do not want always to add the ID to exclude from the query.
The easiest is by category as demonstrated above .
** Edit I **
Just for the sake of it - (I still recommend the cetegory method) r
Even if I dislike custom-fields when they are overused - this is another way that change the query by assigning a custom field :
function o99_my_rss_filter_by _field( $where, $wp_query = NULL ) {
global $wpdb;
if ( !$wp_query ) global $wp_query;if ( $wp_query->is_feed ) {
$posts = get_posts( array( 'meta_key' => 'norss' ) );
if ( $posts ) {
foreach( $posts as $post ) {
$exclude .= $post->ID . ',';
}
}
$exclude = substr( $exclude,0, strlen( $exclude )-1 );
$where .= ' AND $wpdb->posts.ID NOT IN ( ' . $exclude . ')';
}
return $where;
}
add_filter( 'posts_where', 'o99_my_rss_filter_by _field', 1, 4 );
We have a MediaWiki wiki. I'd like to be able to report how much collaboration is going on and I thought of the following graph: number of authors per page. So the data would be like this:
#Pages #Authors
20 1
10 2
25 3
etc. This would show that 20 pages have only 1 author, 10 have 2, 25 have 3, ...
Does anyone know of a way of getting this information?
This information would also somehow need to be shown over time - so if anyone has information on how to do this I'd be grateful. (E.g. last months 25% of pages had 2 or more authors, this month it is 30%).
This not exactly what you wanted, but it might be a good start. It's a simple special page whose only purpose is to display page names and number of authors.
$wgAutoloadClasses['SpecialPagesAuthors'] = $IP . '/additions.php';
$wgSpecialPages['PagesAuthors'] = 'SpecialPagesAuthors';
class SpecialPagesAuthors extends SpecialPage {
function __construct() {
parent::__construct( 'PagesAuthors' );
}
This is basically just registering the page.
function execute( $par ) {
global $wgOut;
$dbr = wfGetDB( DB_SLAVE );
$output = <<<WIKITEXT
{| class="wikitable"
! Page !! Authors
WIKITEXT;
We put everything in a nice table.
$query_result = $dbr->select(
array( 'revision', 'page' ),
array( 'rev_page', 'page_id', 'page_namespace', 'page_title',
'COUNT(DISTINCT(rev_user_text)) AS unique_authors' ),
null,
__METHOD__,
array( 'GROUP BY' => 'rev_page', 'ORDER BY' => 'unique_authors DESC' ),
array( 'page' => array( 'LEFT JOIN', 'page_id=rev_page' ) )
);
Here we query the database for pages and number of authors (which is essentially the number of unique user names and IPs who edited the page).
foreach( $query_result as $row ) {
$title = Title::newFromRow( $row );
$page_title = $title->getPrefixedText();
$output .= <<<WIKITEXT
|-
| {$page_title} || {$row->unique_authors}
WIKITEXT;
}
$dbr->freeResult( $query_result );
Here we output the page name and number of authors to the table and free the DB query result.
$output .= "|}";
$this->setHeaders();
$wgOut->addWikiText( $output );
}
}