Hi I want to change the "add to cart" button url on my single product page so when we click it , the button will redirect to another website (amazon).
Ps. im not a coder but simple code might work for me
As Mentioned the description, you want to redirect to different page after the add to cart action.
So, You can put the below code in functions.php file
function redirect_after_add_to_cart( $url ) {
return esc_url( get_permalink( get_page_by_title( 'Your Page Title' ) ) );
}
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_after_add_to_cart', 99 );
Thanks!!!
Woocommerce works with a hook system, you can redirect the URL of your add to cart button with a php shortcode but, you can also use the plugin: Woocommerce Add to cart custom redirect. The best way for you if you don't know how to use php shortcode :)
link : https://fr.wordpress.org/plugins/woocommerce-add-to-cart-custom-redirect/
Related
I have created a registration form using Elementor Page Builder. Now, I want to redirect the user to a different page if he/she is trying to access that registration page after logging in.
Is there any Elementor hook available for that? I know the WordPress function called is_user_logged_in().
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 12 ) )
{
wp_redirect( get_permalink( 32 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
You should get the ids of the page where the form is and the id of the page you want to redirect the user to.
Code goes in your child theme functions.php file
Reference: here
The 'Content Area Not Found' error might appear on Elementor designed sites when you use that snippet and try to edit page of ID 12 (in your example) in certain cases.
To avoid this, add the following code before the if-statement of your snippet:
if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
return;
}
How do i do this, is there a good plugin? can't find any. I have tried adding code but cannot and can't find anything. All i need is a back button, a back button on my product pages... help please!
You can use the "woocommerce_before_single_product" hook and add the button to shop URL
add_action('woocommerce_before_single_product', 'add_back_button_callback');
function add_back_button_callback() {
$shop_url = get_permalink( woocommerce_get_page_id( 'shop' ) )
echo 'Back';
}
I have a WordPress shopping site. for the time being I want to just disable the checkout option from my site until I update all the price of the products. I tried searching over net for different solutions. but could not find any suitable solution. I am expecting to get help from here. thanks in advance. :)
remove_action( 'woocommerce_proceed_to_checkout',
'woocommerce_button_proceed_to_checkout', 20);
You can just disable all the payment options at WooCommerce->Settings page. That should refrain user from completing the order until you done with your price update.
Update:
If you want to entirely remove the button from the view, then you may need to modify the WooCommerce file. Edit the below files:
path: /woocommerce/templates/cart/cart-totals.php
//search woocommerce_proceed_to_checkout and comment the line
//this will remove the button from cart page
<?php //do_action( 'woocommerce_proceed_to_checkout' ); ?>
path: /woocommerce/includes/wc-template-functions.php
//search woocommerce_widget_shopping_cart_proceed_to_checkout and comment the line
//this will remove the checkout on the cart menu display
//echo '' . esc_html__( 'Checkout', 'woocommerce' ) . '';
I have an article with several pages in my wordpress blog. if for example i have the following link in my blog :
http://example.com/heartbreaking-photos
any idea how can i change the link of the second page from
http://example.com/heartbreaking-photos/2
to http://example.com/heartbreaking-photos/CUSTOM-STRING
CUSTOM-STRING aimed to be a custom title inside the page
To achieve this, you will need to do 2 things:
Disable the default WordPress canonical redirect - this is necessary, because WordPress will always redirect to the /2/ page when it encounters the page parameter in the URL or query args.
Add a custom rewrite rule to direct your custom title to the second page of your page - this is essentially necessary to allow the link format that you want.
In terms of code, this is what you need (this is a working solution, I've just tested it locally):
// Removes the canonical redirection
remove_filter( 'template_redirect', 'redirect_canonical' );
// Add custom rewrite rules
add_action( 'init', 'my_add_custom_rewrite_rules' );
function my_add_custom_rewrite_rules() {
// Slug of the target page
$page_slug = 'heartbreaking-photos';
// Page number to replace
$page_num = 2;
// Title you wish to replace the page number with
$title = 'custom-string';
// Add the custom rewrite rule
add_rewrite_rule(
'^' . $page_slug . '/' . $title . '/?$',
'index.php?pagename=' . $page_slug . '&page=' . $page_num, 'top'
);
}
There are three things you might want to configure or change here:
$page_slug - this is the slug of your page, in your case this is heartbreaking-photos
$page_num - the number of your pagination page, in your case this is 2
$title - the title you wish to use instead of your page number 2.
Feel free to alter the code as you wish, or copy it to cover more additional cases, similar to this one.
EDIT
Important: Once you use the code, go to Settings > Permalinks and click the "Save Changes" button. This will rebuild your rewrite rules, and is necessary for the solution to work.
Hope that helps. Let me know if you have any questions.
You can try this codex. Pass the arg and you will get page id, page title and use those
https://codex.wordpress.org/Function_Reference/get_pages
Or you can call page title by page id
$pagetitle= get_post_field( 'post_title', $page_id );
Ok, so basically you don't want to display the navigation link under the page (use css or modify the post template in the child theme) and add your custom link. If I understand it well:
Remove navigation links (depends on your theme, but basically):
.nav-links { display: none; }
You can add the custom link through function + custom fileds:
create a custom field, for example "my-url" in your post, see codex: https://codex.wordpress.org/Custom_Fields
add to your functions.php (in the child theme or in a custom site plugin):
function my_page_add_to_content( $content ) {
if ( ! empty(get_post_meta( get_the_ID(), 'my-url', true ) ) {
$content .= 'URL TEXT HERE'
}
return $content;
}
add_filter( 'the_content', 'my_page_add_to_content' );
I tried adding a custom button in BuddyPress profile page using below mentioned code. But when I added that code, only Name & Profile picture was appearing & no other content generated through BuddyPress was appearing:
function mapbtn_custom_button() {
echo '<div class="mapbtn">map<div>';
}
add_filter( 'bp_before_member_header_meta', 'mapbtn_custom_button' );
You're trying to hook a filter to an action call.
Try this instead:
add_action( 'bp_before_member_header_meta', 'mapbtn_custom_button' );