Hi I am looking how to get a permalink to a woocommerce my account page endpoint. For example edit-address or orders.
I tried this which I know can't possibly be right, it also appends a 0 onto the end of the link.
get_permalink( get_option('woocommerce_myaccount_page_id') )+"orders";
You should use wc_get_endpoint_url(), it will get endpoint value you set in Woocommerce settings so if you change it one day, your URLs will be updated.
wc_get_endpoint_url('orders', '', get_permalink(get_option('woocommerce_myaccount_page_id')))
Available endpoints are :
view-order
edit-account
dashboard
orders
downloads
edit-address
payment-methods
customer-logout
Replace your code with this
get_permalink( get_option('woocommerce_myaccount_page_id') ) . "orders";
PHP concatenation is dot symbol not plus symbol. https://stackoverflow.com/a/1866194/1593365. Your code seems right only
Related
hello i am using REST API of woocommerce REST API ,
i want to get product by category . when i pass this url i got all product .
https://www.ezdarshan.com/wc-api/v2/products/?consumer_key=ck_dbf0f35e37dc0xxxxxxxxxxxb31d2&consumer_secret=cs_ea299e9b86xxxxxxxxxxxxxxf785a9f77ec7
But when i use filter like this : ?category=56,37
Again i got all product but i want only product which related to these category
i Follow this docs : https://woothemes.github.io/woocommerce-rest-api-docs/?php#list-all-products
Some on help me
I just resolved similar issue. Use slug instead of id / name. It worked for me.
https://yourwebsite.com/api/user/proxy/products/?filter[category]=<SLUG OF CATAGORY>
Correct: (note the trailing slash is removed)
https://yourwebsite.com/api/user/proxy/products?filter[category]=<SLUG OF CATAGORY>
This might be little late to answer but might be helpful for others
According to the new wordpress REST API version this worked for me
https://www.xxxx.com/wp-json/wc/v3/products?category=categoryid
I need help with this: I need that the url of the downloadable products link with an external url. I´m trying to add a custom field and replace the filters woocommerce_product_file and woocommerce_product_file_download_path but it didn't worked, I think because I can´t call to the product data from the order. Someone did this? Thank you for your help!
The code doesn't works. Now is something like:
*function mostrar_campo_personalizado_en_order($file_id){
global $wpdb, $woocommerce;
echo get_post_meta($file_id, 'downloadable_url', true);
}
add_filter( 'woocommerce_product_file', 'mostrar_campo_personalizado_en_order', 10, 1 );
add_filter( 'woocommerce_product_file_download_path', 'mostrar_campo_personalizado_en_order', 10, 1 );*
I don´t know if I´m working in the correct way, I need to change the url of the downloadable products because woocommerce internally routed. Because I couldn't modify him, I intente removal and display a custom post field. The page is in a test server because the site is on line. The url of the tester server ishttp://lab.jus.raffles.com.ar/my-account/ but you need credential to come in:
user: paula
pass: 5VPeGgAHWzYX1T
I have been trying to associate CUSTOM data to each of my WP POSTS using the following piece of code :
if($condition === true){
if ( ! update_post_meta ($post_id, '_someData', $someVariable) ) {
add_post_meta($post_id, '_someData', $someVariable);
}
}
However, seems like the META VALUE is RESET to default i.e. Zero OR Blank. Our WordPress website has around 40 plugins, and I think one of these WordPress plugins, is coming in my way of doing things. All of my logic works fine, on a demo WordPres website. Is there a way for me to have total control to set the META Value for a given POST ? Also, is there a way where I can be notified that the META Key is about to change and then I can decide whether OR not to change the Meta Value ?
Any pointers or reference URL's can be of great help. Thanks !
You only need to call update_post_meta in either scenario. Calling add_post_meta() is not necessary and could be causing this problem.
From the codex:
The function update_post_meta() updates the value of an existing meta key (custom field) for the specified post.
This may be used in place of add_post_meta() function. The first thing this function will do is make sure that $meta_key already exists on $post_id. If it does not, add_post_meta($post_id, $meta_key, $meta_value) is called instead and its result is returned.
I was wondering how to change the excerpt depending on category in WordPress. I have changed the default amount but I need this amount for some boxes on the home page and I need it to display more words on the blog page of the website.
Thanks,
Charlie
I would suggest a custom excerpt that you can use and change as you wish. I've recently done a complete answer on the_excerpt(). This comes from that answer. You can also check out the complete answer here
CUSTOM EXCERPT LENGTHS
Sometimes you need to display simple excerpts of different lengths and it is not viable to write an excerpt for every post/function/page. Here is a nice small little function using wp_trim_words
function wpse_custom_excerpts($limit) {
return wp_trim_words(get_the_excerpt(), $limit, '' . ' …' . __( 'Read more »', 'wpse' ) . '');
}
What this little function do is taking get_the_excerpt trimming that to $limit set by the user and returning the text with a read more link at the end.
You can call this excerpt as follow in your template
echo wpse_custom_excerpts($limit);
where $limit will be your word count, so an excerpt of 30 word will be
echo wpse_custom_excerpts(30);
Just one thing to remember here, if you set your limit to more that 55 words, only 55 words will be returned as the excerpt is only 55 words in length. If longer excerpts are needed, use get_the_content instead.
Hard to define the Title of this Question....
I want to create a nice readable permalink structure for my 2 custom post types (CPT).
My first CPT "family" has the following rewrite-slug "family/%postname%" (all works fine)
The second CPT "childs" has a metabox where I can select the parent_id-field by choosing a CPT "family" where the child-CPT belongs to. That also works great.
Now I set the rewrite-slug for "childs" to "%parent_post_url%/child/%postname%" so that I can get the following URL "family/the-griffons/child/peter" . But when I call this URL wordpress displays a not-found-page. The crazy thing is that if I set the rewrite-slug hard to "family/the-griffons/child/%postname%" I can call the URL (both URLs are the same!!!)
So why toes WP throws an error when I try to get the URL dynamically but not when I hardcode the URL??
The child-parent relationship you think you have is not quite there. Based on what you've told us so far, it seems that all you have is a custom field denoting the "pseudo-parent" id. So what your question should really read is
How do I rewrite the first part of the cpt url, based on the cpt custom field value ?
because, as far as wordpress is concerned in your case, that's all that "parent id" really is- a custom field value.
you can try following the last part(Part 3.) of this tutorial, keeping in mind, that you'll want the actual path of the url of the "parent id" and not the cf "parent id" value itself, you'll have to implement something along the lines of:
$parent_id = get_post_meta($post_id, "your_cf_key_for_parent_id", true);
$full_parent_post_url = parse_url( get_permalink( $parent_id ) );
$parent_post_url = $full_parent_post_url['path'];
if(!$parent_post_url) { $parent_post_url = "default-fallback" }
$permalink = str_replace(‘%parent_post_url%’, $parent_post_url, $permalink);
return $permalink;
another relevant stackexchange answer:
using-custom-fields-in-custom-post-type-url
BUT as #c0ns0l3 mentioned using custom taxonomies IS the proper way to go about this.