Right now, in woocommerce the shortcode [woocommerce_my_account] displays the entire "My Account" page with all the tabbed options.
I only want to show the order details (found under the Orders tab) on a separate page.
So, can I just use the woocommerce template orders.php (woocommerce/templates/myaccount/orders.php) and use it on a blank new page or is there a better way to go about it?
Woocommerce has function woocommerce_account_orders() which includes Orders template. You can follow the below steps to display only orders on a separate page.
Step-1: Place below code in your theme's functions.php (Place in child theme if you have created).
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
Step-2: Place shortcode [woocommerce_orders] in any pages in admin side and check on front end.
Above Code will display orders if customer is loggedin otherwise it will display woocommerce's login/registration page.
If you want to hide "Orders" tabbed option which is on "My Account" Page then go to Admin Side and then Woocommerce > Settings > Accounts (tab) where you can see "My account endpoints", empty "orders" field there. It will hide "Orders" from frontend "My Account" page.
Edit: Make sure that you check on frontend loggedin as "Customer" user and that customer user has atleast one order placed otherwise blank page will display there.
Related
I designed a WooCommerce template for a customer. Now he wants to remove prices and visitors only add what they want to the list. So there will be no payment method. s:
- I can't change plugin or database. All data must remain how they are.
- I need to remove prices from all over the site. where ever they are. Cart, wishlist, single page & etc.
- I need to change payment method to something like submit list.
- at the end after submit list page there must be a contact info page.
please help.
You can hook into wc_price and remove the prices there
function my_filter_wc_price( $price ){
return '';
}
add_filter( 'wc_price', 'my_filter_wc_price' );
Then you can hook into parse_query and redirect the checkout page to the contact page.
function my_parse_query(){
if( is_page( wc_get_page_id( 'checkout' ) ) ){
wp_redirect( '/contact' );
exit;
}
}
add_action( 'parse_query', 'my_parse_query' );
That will stop people from being able purchasing things. Just hiding the price with CSS will not. They will still be able to craft URL's to add to cart, and find the cart / checkout pages.
since I found no other way I decided to do it width CSS and translation.
I removed all prices by display:none;
and I translated all the strings which are about shop and price.
I am trying to develope an password role protection on my web. What I need to achieve is to redirect visitors to the login wp-login.php when they try to enter an specific page if they are Suscriptors. WordPress don't gives us that option so I had to develop myself (I don't want to use external plugins).
I had the role filter, but I can't find the filter to control wich page is being loaded in order to redirect the visitor.
Add this code in your Function.php file.
using template_redirect action hook
This action hook executes just before WordPress determines which template page to load. It is a good hook to use if you need to do a redirect with full knowledge of the content that has been queried.
function template_redirect_fn()
{
//add you logic to perform your task
//Redirect page to login page
if(is_page ('about-us'))
{
$loginUrl = "LOGIN URL";
wp_redirect($loginUrl);
exit();
}
//if more then one page then used this
if( is_page( array( 'about-us', 'contact', 'management' ) )
// about us, or contact, or management page is in view
}
add_action( 'template_redirect', 'template_redirect_fn' );
is_page(Page ID OR title OR slug of you want to check )
When a User Buys a Product he can generate up to 3 Serial Keys for his Product. This works fine so far. The User can see his Serials always in "my account"
The Data gets stored in the Database: Table=Usermeta Meta=Product_Serial
So from a Users Perspective evrything works fine but from the Admin Perspective not because the admin canĀ“t see how much Serials the Customer has created and also he cant see the Serials the User is using.
Now I have created a Custom Field in the Theme functions.php with this code:
add_action( 'add_meta_boxes', 'add_meta_boxes' );
function add_meta_boxes()
{
add_meta_box(
'woocommerce-order-my-custom',
__( 'Order Custom' ),
'order_my_custom',
'shop_order',
'side',
'default'
);
}
But from here I don't know how to read out the Serial Key so the admin can see it. :( Any ideas ?
May be i am displaying data in wrong place in your order detail page. But you can check there is multipe hook avilable for this woocommerce/inculdes/admin/meta-boxes-/view/html-order-items.php.
I just take one this hook. Please add this code in functions.php
function my_function_meta_deta() {
echo "I am here";
}
add_action( 'woocommerce_admin_order_totals_after_refunded','my_function_meta_deta', $order->id );
As coder said there is multiple hooks you can also try this out.
add_action('woocommerce_admin_order_data_after_order_details', 'my_custom_order_manipulation_function');
function my_custom_order_manipulation_function( $orderID ) {
//dynamic functionalities / static html to display
}
Credits : Add order metadata to WooCommerce admin order overview
When user clicks 'Proceed to checkout' at the cart page, I would like to send him to custom URL. I used this filter in functions.php
add_filter('woocommerce_get_checkout_url', 'dj_redirect_checkout');
function dj_redirect_checkout($url) {
global $woocommerce;
$checkout_url = 'http://my-custom-url.com';
return $checkout_url;
}
However, in this case this filter is triggered on the checkout page as well and I would like to trigger it on the Cart page and after the click 'Proceed to checkout' only.
Please, advise.
Thank you,
What you can do is, use conditional tags in your code :
add_filter('woocommerce_get_checkout_url', 'dj_redirect_checkout');
function dj_redirect_checkout($url) {
global $woocommerce;
if(is_cart()){
$checkout_url = 'http://my-custom-url.com';
}
else {
//other url or leave it blank.
}
return $checkout_url;
}
EDITED :
If you want to redirect users to custom URL after click on Add to card button then you can use below code:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout() {
global $woocommerce;
$checkout_url = 'http://my-custom-url.com';
return $checkout_url;
}
Second Edit :
What you can do for that is simply make on template for check out page :
<?php
/**
* Template Name: Custom Template
*
*Custom Template for the woocommerce checkout page
*
*/
get_header();?>
Click Me!
<?php
get_footer();
?>
Here in above code, I have made template with name of custom Template and save it with the wtemplate.php in the theme folder.
Next step is to Create New Page. I have created new page with the name of Simple Template(You can name it whatever you want). And in sidebar, there is option of template(you can see below image for reference) where I have selected Custom Template as a template.
Now Go to the Dashboard > WooCommerce > Settings > Checkout ** and in that, there is option of selecting checkout page(You can find in below picture). Select the page that you have made(I have made **Simple Template as you can see in above code) and save it.
Now whenever user will click on Proceed to Checkout, they will redirect to that custom template.In custom template, you can link to the woocommerce default checkout page(In my case, It is having page_id=6).
Hope it helps you.If you have any doubt related to this, you can give comment.
I have two distinct products in a WooCommerce cart. One is a ticket, the other is a fee that must be paid before the user can upload a file (which is being handled by a Gravity Form I've created).
Currently, if I put the link to the page with the Gravity Form on the Order Received page, if someone purchases just a ticket, they would see this link and it would be confusing.
Is there a way to either have unique confirmation pages once a purchase is complete based on the product purchased?
If not, are there conditional tags or some kind of hook or filter that would only show the link to the Gravity Form on the Order Received page if the "fee product" is purchased (possibly based on product ID or category ID)?
I did find this code snippet:
https://sozot.com/how-to-hook-into-woocommerce-to-trigger-something-after-an-order-is-placed/
But when I try this:
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {
$order = new WC_Order( $order_id );
$myuser_id = (int)$order->user_id;
$user_info = get_userdata($myuser_id);
$items = $order->get_items();
foreach ($items as $item) {
if ($item['product_id']==154) {
echo '<h3>If you are submitting a script, please click here to submit your script.</h3>';
}
}
return $order_id;
}
Nothing gets displayed on the Order Details screen. Oddly enough, if I try and use wp_redirect and force a redirect the page, it "works", but it breaks the page and causes some strange embedding of the site within the checkout page.
After beating on this incessantly, I finally found what I was looking for, so I thought I'd post it. In my case, I wanted to customize the Order Detail/Confirmation page with a link to a form, but only when a certain product is purchased.
If you want something similar, put this in the order_details.php template:
global $woocommerce;
$order = new WC_Order( $order_id );
/* This two lines above should already exist, but I have them here so you can
see where to put the code */
foreach($order->get_items() as $item) {
$_product = get_product($item['product_id']);
if ($item['product_id']==154) {
// Do what you want here..replace the product ID with your product ID
}
}
I also tested this by inserting a wp_redirect within the if statement and it seemed to work great, so I imagine you could customize this code with a bunch of if/elseif statements that redirect to different landing pages depending on the product purchased! Hopefully this helps someone!