/*
 Theme Name:   Bricks Child Theme
 Theme URI:    https://bricksbuilder.io/
 Description:  Use this child theme to extend Bricks.
 Author:       Bricks
 Author URI:   https://bricksbuilder.io/
 Template:     bricks
 Version:      1.0
 Text Domain:  bricks
*/
// Remove Cross Sells from the default position on the cart

remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' ); 
 
// ---------------------------------------------

// Custom Bricks Builder tag to return user first name if available. If not available, return display name.

function get_current_user_friendly_name() {
    // Get the current logged-in user object.
    $user_info = wp_get_current_user();

    // Check if a user is logged in (ID will be 0 if not).
    if ( ! $user_info || 0 === $user_info->ID ) {
        return ''; // Return empty string if no user is logged in.
    }

    // Get the first name and trim any excess whitespace.
    $first_name = trim( $user_info->first_name );

    // Check if the first name exists and is not empty.
    if ( ! empty( $first_name ) ) {
        // Return the user's first name.
        return $first_name;
    }

    // Fallback: Return the user's display name if the first name is empty.
    return $user_info->display_name;
}

add_filter( 'bricks/code/echo_function_names', function() {
  return [
    'get_current_user_friendly_name',
  ];
} );