Add custom button in profile page of BuddyPress - wordpress

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' );

Related

Display a custom field under WooCommerce single product image

I am trying to display a custom field on Woocommerce single product page just under the product image.
Does anyone know the hook for this custom field?
You can achieve the above by adding in follows hook -
function add_custom_field_just_under_image(){
global $product;
echo "Your custom code goes here";
}
add_action( 'woocommerce_product_thumbnails', 'add_custom_field_just_under_image', 10 );
Codes goes to active theme's functions.php

Woocommerce - change "add to cart" button url

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/

How to create separate log-in and registration pages in WooCommerce

I want to seperate the login and registration page for woocommerce.
(there is a different solution that I don't get to work here:
Separate registration page in WooCommerce website)
I duplicated the form-login.php and renamed it to register.php
In the register.php template I deleted the login-content.
I want to add a page to wordpress and add the register.php template with a SHORTCODE to that page. How do I do this??
Then I could add a Register Link to the Login Page with
<?php _e( ' Register' ); ?>
and the new shortcode register page is loaded.
mmmhhh...
what do I have to add to the duplicated login /now register.php, that it can be loaded to any page with a SHORTCODE? that would be interesting.
Thanks for helping out!Best wishes, Mika
A more straightforward way to do this is to save the contents of the original form-login.php as form-login-single.php, and then replace the file form-login.php with:
<?php
if( isset($_GET['action']) == 'register' ) {
wc_get_template( 'myaccount/form-register.php' );
} else {
wc_get_template( 'myaccount/form-login-single.php' );
}
This way you don't need to modify your functions.php further, plus you don't run into any trouble with double-rendering of the register form that I got when using #Hassan-ALi's method.
You can create a copy of the Woocommerce form-login.php and name it form-register.php. The form-login.php is located in /woocommerce/templates/myaccount/ folder.
Then in the form-login.php you can create a link to the form-register.php using this code
register
// Separete Login form and registration form
add_action('woocommerce_before_customer_login_form','load_registration_form', 2);
function load_registration_form(){
if(isset($_GET['action'])=='register'){
woocommerce_get_template( 'myaccount/form-registration.php' );
}
}

Wordpress Hook into page body

I am working on a plugin that will be used to add a customized form of Acuity Scheduling for a specific page. I want to add the scheduling form after the menu and page title on one particular page. Here is my current code:
add_action( 'template_redirect', 'check_if_acuity_page');
function check_if_acuity_page(){
if(is_page('Schedule Page')){
add_action( 'add to acuity', 'display_acuity_scheduling_api');
}
}
function display_acuity_scheduling_api(){
echo '<div style="margin-top: 25px;">"Code to add Acuity Schedule to page"</div>';
}
The 'add to acuity' is a custom action hook that is currently added in the header.php file of the theme I am using. It adds the schedule at the very top of the page currently, so I can at least get it on the proper page, but it is located above the Menu and Title for the page. I am working on creating a custom layout and using PHP code to modify the page depending on what the user chooses, which is why I am not just using a simple embed code.
I am new to Wordpress Plugins and Hooks so I am not sure if I am supposed to be using an action or filter hook for this. Any help would be very appreciated.
To add code just before content which is below page title use following code:
function check_if_acuity_page(){
if(is_page('Schedule Page')){
echo '<div style="margin-top: 25px;">"Code to add Acuity Schedule to page"</div>';}
}
function add_code_before_content($content){
$acuity_page = check_if_acuity_page();
$content = $acuity_page.$content;
return $content;
}
add_filter('the_content','add_code_before_content');
Hope this helps.
WordPress action hooks are a means of providing a way for other developers to insert their own code in specific locations within your code, in order to change or expand the functionality of your code.
So in this case you should be using an action hook.
The concept of filters and hooks is explained in this article.
So by placing the add_action function in your template after the menu and page title you can hook onto it with a function.
In your page template after the menu and page title:
add_action( 'add to acuity', 'check_if_acuity_page');
In your functions.php:
function check_if_acuity_page() {
if(is_page('Schedule Page')) {
echo '<div style="margin-top: 25px;">"Code to add Acuity Schedule to page"</div>';
}
}

display custom fields automatically when a custom post type is displayed

I am trying to automatically display all the custom fields of a custom post type alongside it's title and content.(Not in admin but on my actual site)
I need to be able to do this with an action hook or filter, rather than creating a template.
After scouring the web I was able to find the 'publish_{custom_post_type_name}' hook:
function my_cool_hook() {
echo get_post_meta($post->ID, 'my-custom-field-name', true);
}
add_action( 'publish_past_symposia', 'my_cool_hook' );
but it doesn't seem to do anything when I view my published custom post type on my site. Any ideas?
add_action( 'publish_past_symposia', 'my_cool_hook' );
This hook triggered only if PUBLISH post type.
YOu need to trigger the hook on web part - so...
add_filter('the_content', 'my_cool_hook');
function my_cool_hook($content){
return $content.get_post_meta(get_the_id(), 'my-custom-field-name', true);
}
now the content body filtred and your string from custom fields added.

Resources