How to remove URL from WooCommerce My account order number - php

I want to remove the URL from the WooCommerce My account Orders page and I really don't know how to do it by editing functions.php. Does anyone have any suggestions? Thank you!
order details url
I tried some of the answers I found on StackOverflow but I doesn't seem to work.

Remove the existing order-number column using the first hook as it prints the order number along with the link.
Add a custom order order-number column to print as per your requirement using the second hook
function remove_defualt_order_number_column($columns) {
unset($columns['order-number']);
$custom_order_number = array('order-number-custom' => __('Order', 'woocommerce'));
$columns = array_merge($custom_order_number, $columns);
return $columns;
}
add_filter('woocommerce_account_orders_columns', 'remove_defualt_order_number_column', 10, 1);
add_action('woocommerce_my_account_my_orders_column_order-number-custom', 'add_custom_order_number_column', 10, 1);
function add_custom_order_number_column($order) {
echo esc_html(_x('#', 'hash before order number', 'woocommerce') . $order->get_order_number());
}

Related

Add_filter to add new column to Woocommerce product attributes table (Attributes add / edit page)

I would like to add a new column to the Attributes table on the Attributes add / edit page within Woocommerce / Wordpress admin, using the Wordpress / PHP add_filter command.
As a reference, to add columns in WordPress admin to the Woocommerce All Products add / adit table, the following filter works:
add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 )
The All Products page is:
wp-admin/edit.php?post_type=product
and I see the add_filter follows the pattern:
manage_edit-{POST_TYPE}_columns
I cannot find or work out what the filter should be to do the same on the Woocommerce Attributes add / edit page. The page URL for that is:
wp-admin/edit.php?post_type=product&page=product_attributes
I've experimented with various combinations using the working filter for the All Products page, but I am not clear how to use add_filter when URL contains both Post Type and Page.
I hope I have explained it clearly. I have searched a lot for the answer, both here and in Google, so if there is a duplicate, I genuinely have not seen anything close to what I'm looking for.
Thanks in advance!
You could, but i don't recommend it, abuse the get text filter for this
something like this
add_filter('gettext', 'my_custom_column_function', 1, 2);
function my_custom_column_function($text, $domain=""){
if($domain === 'woocommerce' && $text === 'Order by'){
$text = $text . "</th><th>My Column Name";
} else if($domain === 'woocommerce' && ($text === 'Name' || $text === 'Name (numeric)' ||
$text === 'Term ID' || $text === 'Custom ordering')){
// Some code here to create the output as text string
$example = 1 + 2;
$text = $text . "</td><td>" . $example;
}
return $text;
}
It is only possible to either put the column in front of or after the "Order By" column in this way and I don't know what information is available in the code for using in the output, as this is a very hacky way to do thing I don't recommend using this method
I don't think it is possible, i had a quick peek at the sourcecode of woocommerce. The function that outputs the list you are talking about is located on line 296 of includes/admin/class-wc-admin-attributes.php and is outputting a static column layout.
https://github.com/woocommerce/woocommerce/blob/aa89afcf957beb6a387ad7d5d36fd7d95b3a353b/includes/admin/class-wc-admin-attributes.php

How can I find related learndash course id from woocommerce product object?

I have woocommerce integrated with LearnDash. Now I am trying to get the selected course (related course) from the woocommerce product object or any other way (by woocommerce product id). There must be a way as buying the product unlocks the course. Just cannot find it.
Could anyone help?
The related course data is stored as post_meta on the WooCommerce Product.
You can see this in wp-content/plugins/learndash-woocommerce/learndash_woocommerce.php line 150 or so when the render_course_selector() function updates the post meta with '_related_courses' is it's key included in the $_POST on saving the product.
For my use case, I needed to get it in the outgoing emails so I did this:
function my_plugin_add_course_link_to_emails($item_id, $item, $order, $plain_text)
{
$html = '<div class="email-course-link">';
$related_courses = get_post_meta($item->get_product_id(), '_related_course');
foreach ($related_courses as $related_course) {
$id = $related_course[0];
$url = learndash_get_course_url($id);
$html .= 'Course Link';
}
$html .= '</div>';
echo $html;
}
add_action('woocommerce_order_item_meta_start', 'my_plugin_add_course_link_to_emails', 10, 4);
The magic line that answers your question though is this one:
$related_courses = get_post_meta($item->get_product_id(), '_related_course');
Any variation of the above should do the trick for you.

WooCommerce - Add content on the thank you page by the shipping method

I would like to place my own content (in my case a shortcode) on the thank you page at WooCommerce after completing the order, which depends on the shipping method.
So for example:
Shipping Method 1: Content 1
Shipping Method 2: Content 2
Shipping Method 3: No content
I have already found something for text here, but i dont get the shortcode inserted. Alternatively I have tested what works with the shortcode here, where the dependency on the shipping method is missing.
Maybe someone can help me to implement this.
Ideally the content should be above the table with the order information.
Thanks a lot!
May be the way you added the shortcode to the thank you text can be the issue.
See the following shortcode function called avengers which i created for demo.
function call_avangers( $atts ){
return "<p>Avengers . . . . Assemble !!!</p>";
}
add_shortcode( 'avengers', 'call_avangers' );
You can display this shortcode in thank you page using the below function
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
if( $order->get_shipping_method() == 'your_shipping_method_here' ) {
$text .= do_shortcode('[avengers]');
}
return $text;
}
The basic thing is you have to call do_shortcode('your_shortcode_name')

How do I add order note on (advanced) custom fields update?

I'd like to add an order note to log the time I added tracking number to existing order. I'm using Advanced Custom Fields to store trackings. Tried function below, and it breaks my site:
function tt_add_tracking_note( $order ) {
$tt_order = $order->id;
if (get_field('tt-track', $tt_order)) {
$tt_tracknum_note = 'Added tracking number ' . the_field('tt-track', $tt_order);
}
$tt_order->add_order_note( $tt_tracknum_note );
}
add_action( 'woocommerce_process_shop_order_meta', 'tt_add_tracking_note', 10, 2 );
What is wrong and how do I add a note the right way?

WP Ecommerce: Display the "Order Notes" in Sales Log

I have the following function that adds a column in the Sales Log so that I may show the Order Notes. Adding the column is good and showing the id of each item ($item->id) as test is good. Where I am getting stuck is how to display the actual order notes for each item.
Tried numerous things including ($purchlog_notes->notes);
This adds the column (all good)
`function addPurchaseLogColumnHead( $columns ){
$columns['OrderNotes']=__('Order Notes');
return $columns;
}
add_filter( 'manage_dashboard_page_wpsc-purchase-logs_columns', 'addPurchaseLogColumnHead');`
This is where I want to show Order Notes content for each sale (issue)
`function addPurchaseLogColumnContent( $default, $column_name, $item ) {
if ($column_name == 'OrderNotes'){
echo $item->notes;
}
}
add_filter( 'wpsc_manage_purchase_logs_custom_column' , 'addPurchaseLogColumnContent', 10, 3);`
Appreciate any ideas.
Thank you.

Categories