woocommerce my account page showing posts - wordpress

I'm working on a WordPress plugin where I've to create a custom frontend page. After adding the add_rewrite_tag, my custom frontend page works and all the woocommerce pages (endpoints) works fine but the /my-account page does not.
It shows the posts page. Removing the add_rewrite_tag fixes the /my-account page.
function customop_custom_output() {
add_rewrite_tag( '%pn-projects%', '([^/]+)' );
add_permastruct( 'pn-projects', '/%pn-projects%' );
flush_rewrite_rules();
}
add_action( 'init', 'customop_custom_output' );
Am I missing something here?

Related

How to remove the original link of a post in Wordpress after using post_link and add_rewrite_rule to change the link?

I changed the permalinks of my posts using post_link, adding "/test/" to it.
So for example www.website.com/this-is-fun/ is now having the permalink www.website.com/test/this-is-fun/
This permalink is correctly showing in the admin, when editing a post, and also on the website the link to the post is the new one.
However, when I open this link it is not working, I get a 404. I was able to fix that with a add_rewrite_rule, but now my problem is that BOTH urls exist. I want only the new one to exist.
Am I making a mistake in the post_link part, is there a way you can automatically disable the original link and make the new one work? Or should I use add_rewrite_rule to disable the original? Or is there another way?
This is my code:
add_filter( 'post_link', 'custom_permalink', 10, 3 );
function custom_permalink( $permalink, $post, $leavename ) {
$permalink = home_url('/test/' . $post->post_name .'/' );
return $permalink;
}
add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
add_rewrite_rule(
'test/([^/]+)(?:/([0-9]+))?/?$',
'index.php?name=$matches[1]',
'top'
);
}
add_action( 'init','flush_rewrite_rules' );
I know I can change the permalink in the settings btw, but this new permalink will not be for all posts, so I need to do it this way.

Change pagination base slug on WooCommerce archive product page

I want to change pagination slug, currently 'page' to 'strana' on WooCommerce archive pages.
Default setting with urls http://localhost/obchod/ and http://localhost/obchod/page/2/ works fine.
When I change pagination base and resave permalinks it not works.
Final url should look like: http://localhost/obchod/strana/2/
This is my code for changing the pagination base:
function custom_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->pagination_base = 'strana';
}
add_action('init', 'custom_rewrite_rules');
I always resave permalinks on WordPress or I use $wp_rewrite->flush_rules();, but non of these works.
Note that this code works for WordPress pagination, but not for WooCommerce pagination shop pages.
What Am I doing wrong?
First we need to change the format of the links that Wordpress generates. As we need to change the pagination format only for the shop archive, we add a conditional tag is_shop() , so another pagination will stay in old format.
function custom_rewrite_rules() {
global $wp_rewrite;
if(is_shop()) {
$wp_rewrite->pagination_base = 'strana';
}
}
add_action('template_redirect', 'custom_rewrite_rules');
Next, we add_rewrite_rule() to make Wordpress understand the new link format for pagination pages
add_rewrite_rule(
'^obchod/strana/([^/]+)/?',
'index.php?paged=$matches[1]',
'top'
);
obchod here = your shop base, default its shop fow woocommerce stores
Update for test
function custom_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->pagination_base = 'strana';
}
add_action('init', 'custom_rewrite_rules');
add_rewrite_rule(
'^obchod/strana/([^/]+)/?',
'index.php?paged=$matches[1]&post_type=product',
'top'
);

woocommerce : Unable to override single-product template

I am trying to override woo commerce single product template but it won't get overridden.
I have done the following steps:
Added file inside my theme directory.
Added support for Woo-commerce in my functions.php file
add_action( 'after_setup_theme', 'wpse319485_add_woocommerce_support' );
function wpse319485_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
Made sure the debug mode is off in config file
define( 'WC_TEMPLATE_DEBUG_MODE', false );
Checked the status of templates over-riden
Added an h1 tag with test text in it.
I even tried deleting everything but the default template is loaded.
What am I missing ?
I'm not sure if you are still facing this problem. I ran into the very same. After a very frustrating day, tempted to hack the plugin files, I ended up adding woocommerce.php to my theme, containing:
if ( is_product() ) {
wc_get_template( 'woocommerce/single-product.php' );
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
wc_get_template( 'woocommerce/archive-product.php' );
}
This is an adaptation of what I found here:
https://wordpress.org/support/topic/archive-productphp-template-overwrite-not-working/
It did not work without adding
woocommerce/

Woocommerce product images in lightbox ix not showing on product detail page

I have a website where product gallery is not working on product detail page, I have tried to add third party plugin but nothing seems to working.
Here when you click on product image, it should open in lightbox as product gallery.
https://bosheimsmarken.no/produkt/reinrot-te-med-tea-shotnon-binding-subscriptions/
Try to install this plugin and check if there is option to disable this gallery in theme options or woocommerce options.
Product Gallery Slider for Woocommerce by codeixer
Also add this code in your functions.php in active theme
add_action( 'after_setup_theme', 'bbloomer_remove_zoom_lightbox_theme_support', 99 );
function bbloomer_remove_zoom_lightbox_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
remove_theme_support( 'wc-product-gallery-slider' );
}

WordPress custom post type rewrite rule

I'm trying to add a rule for a custom post type. By default, the URL to view post is www.mydomain.com/job/post-slug
What I'd like, is the post also accessible with the following URL:
www.mydomain.com/j/postid
I've tried this in my functions.php file and I also refresh permalinks in admin settings:
function rewrite_short_job_url() {
add_rewrite_rule( '^j/([0-9]+)/?', 'index.php?post_type=job&id=$matches[1]', 'top' );
flush_rewrite_rules( true );
}
add_action( 'init', 'rewrite_short_job_url' );
Doesn't work for me, I'm trying to understand the Rewrite API but cannot find a solution.
I believe you should be using the following:
function rewrite_short_job_url() {
add_rewrite_rule( '^j/([0-9]+)/?', 'index.php?post_type=job&p=$matches[1]', 'top' );
}
add_action( 'init', 'rewrite_short_job_url' );
It's important to keep the post_type var, so that only job posts use that redirect.
You can view a list of WordPress query variables in the Codex.

Resources