j.c
j.c

Reputation: 2882

Woocommerce get product category base permalink

Is there a way to retrieve the product category base permalink?

Thanx.

EDIT

I'm adding this image as an example:
enter image description here

i'm looking for a get_?option?('?product-category-base?') kind of function, in this example it should return only the string: whatever.



EDIT 2

The image i posted is a crop from wordpress dashboard -> Settings -> Permalink and indicates the additional settings -> product-category-base.
I need to retrive the value eventually inserted by admins in the field Product category base, i guess there is a key for a kind of get_option() function...

Thanx.

Upvotes: 1

Views: 4176

Answers (2)

d.p.
d.p.

Reputation: 111

This is (presumably) too late for the OP, but if anyone else comes across it, the option you want is woocommerce_permalinks, and within that the category_base key.

Minimal example (without any checks, etc):

$wc_options = get_option('woocommerce_permalinks');
$product_category_base = $wc_options['category_base'];

Upvotes: 11

Syntax_Error
Syntax_Error

Reputation: 801

EDIT: Then you are looking for the category? At least that explain in the Woocommerce official site

The default category base is product-category. An example would be yourdomain.com/product-category/category-name.

You can get the category (or categories) of a product with:

global $product; 
echo $product->get_categories( ', ', ' ' . _n( ' ', '  ', $cat_count, 'woocommerce' ) . ' ', ' ' );

Original Post

I don't think I understand your question. Do you mean this permalink?

echo $Permalink=$product->get_permalink();

That return this (I edited to omit my site).

http://mysiteurl.com/product/4-pack/

I'm not sure what do you want to do with that? Can you explain more?

Upvotes: 0

Related Questions