Title: Woocommerce Custom post type permalink
Last modified: September 1, 2016

---

# Woocommerce Custom post type permalink

 *  Resolved [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/)
 * I’m using woocommerce with Custom Post Types to enable CPTs to be added to cart
   as a workaround on a running system
 * i’m facing an issue returning the permalink of the CPT as a hyperlink for the
   product name at the cart page and the orders page
 * i’ve tried to filter but i can’t get it to hyperlink the product name as to the
   product url which is a permalink
 * woocommerce 2.6 wp 4.5.3
    thanks in advance
 *     ```
       //item permalink
       add_filter('woocommerce_cart_item_permalink','listing_peramlink',20,2);
       function listing_peramlink($product_permalink,$post){
       if ($post->post->post_type == 'listing_type')
       $product_permalink = get_permalink( get_post_meta($post->id));
       return $product_permalink;
       }
       ```
   
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547267)
 * > i’m facing an issue returning the permalink of the CPT as a hyperlink for the
   > product name at the cart page and the orders page
   > i’ve tried to filter but i can’t get it to hyperlink the product name as to
   > the product url which is a permalink
 * Not sure what you are doing… But if you are a CPT that have the same links for
   the products, this not should work with the WP rewrite rules…
 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547268)
 * Maybe should be better you only change the permalink structure of the products
   in this case.
 *  Thread Starter [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547316)
 * it doesn’t have the same link for the product it has its own system with its 
   own permalink
    i tried renaming the permalink structure for the CPT to be product,
   but it didn’t work i’m using the permalink structure of [http://localhost/sample-post/](http://localhost/sample-post/)
   and a custom slug for the CPT
 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547442)
 * If you rename your CTP to product, for sure you’ll have problems.
 *  Thread Starter [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547446)
 * Yeah i tried, any suggestions?
 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547447)
 * No idea what are you doing and why create a post type to link to products with
   the same permalink structure.
 *  Thread Starter [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547448)
 * Its the same structure but different name of the cpt, woocommerce have “product”
   as the main cpt, ive a running system that have another name for the cpt.
    What
   iam trying to do is when at the cart page i want to link the “cpt product name”
   to its permalink. Right now i cant click on the product name
 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547450)
 * Ok, but if you need to change the link in the cart need to use the `woocommerce_cart_item_permalink`
   filter as are you doing, but this filter don’t return any “post”.
 *     ```
       function my_wc_custom_listing_permalink( $permalink, $cart_item ) {
           // $cart_item returns an array if the cart item data.
   
           return $permalink;
       }
   
       add_filter( 'woocommerce_cart_item_permalink', 'my_wc_custom_listing_permalink', 20, 2 );
       ```
   
 * Here an example of that array: [https://pastebin.com/0cnrRKPr](https://pastebin.com/0cnrRKPr)
 *  Thread Starter [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547482)
 * i was looking for a post when nothing was returning it 😀
 * Thanks Claudio i was able to get it right
 * Best regards
 *  Thread Starter [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547484)
 * i spoke too early
    all products at the cart are returning the same link what 
   i’m doing wrong??
 *     ```
       add_filter('woocommerce_cart_item_permalink','listing_peramlink_cart',20,2);
       function listing_peramlink_cart($product_permalink,$cart_item){
       global $woocommerce;
       foreach ($woocommerce->cart->get_cart() as $cart_item => $value) {
       $product_permalink = get_permalink($value['product_id'] );
       	}
       return $product_permalink;
       }
       ```
   
 *  Plugin Contributor [Claudio Sanches](https://wordpress.org/support/users/claudiosanches/)
 * (@claudiosanches)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547500)
 * > what i’m doing wrong??
 * All?
 * See my example of code and see yours code… Where you can find in my code any `
   $woocommerce->cart->get_cart()` ?
    Why are you looping into all cart products
   to display a single URL? That’s why all products display the wrong URL, since
   always will be for the last product on your loop.
 *  Thread Starter [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * (@ahnabil)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547511)
 * i though i must loop through all the items in cart, i got it right now, thank
   you again 😀

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Woocommerce Custom post type permalink’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [cpt](https://wordpress.org/support/topic-tag/cpt/)
 * [get_permalink](https://wordpress.org/support/topic-tag/get_permalink/)

 * 12 replies
 * 2 participants
 * Last reply from: [ahnabil](https://wordpress.org/support/users/ahnabil/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/woocommerce-custom-post-type-permalink/#post-7547511)
 * Status: resolved