/*
 Theme Name:   Woodmart Child
 Description:  Woodmart Child Theme
 Author:       XTemos
 Author URI:   http://xtemos.com
 Template:     woodmart
 Version:      1.0.0
 Text Domain:  woodmart
*/

/* Product title truncate for all products */
.product-title {
  width: 100%;               /* container full width */
  white-space: nowrap;        /* single line */
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;           /* adjust as needed */
  font-weight: 500;
  cursor: pointer;
  transition: max-height 0.3s ease;
  max-height: 30px;          /* single line height */
}

/* Expanded state on click */
.product-title.expanded {
  white-space: normal;       /* allow multiple lines */
  overflow: visible;
  text-overflow: clip;
  max-height: 500px;         /* enough for full title */
}

/**
 * Enqueue script and styles for child theme
 */
function woodmart_child_enqueue_styles() {
	wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'woodmart-style' ), woodmart_get_theme_info( 'Version' ) );
}
add_action( 'wp_enqueue_scripts', 'woodmart_child_enqueue_styles', 10010 );

/* ==============================
   Quick Shop / See Details Button
============================== */

/* Button Function */
function woodmart_add_quick_button_on_all_products() {
    global $product;

    if ( $product && is_a( $product, 'WC_Product' ) ) {

        // Check if variable product
        if ( $product->is_type('variable') ) {
            $button_text = 'See Details';
            $button_url  = get_permalink( $product->get_id() );
        } else {
            $button_text = 'Quick Shop';
            $button_url  = wc_get_checkout_url() . '?add-to-cart=' . $product->get_id();
        }

        echo '<a href="' . esc_url( $button_url ) . '" class="button quick-shop-button">' . esc_html( $button_text ) . '</a>';
    }
}

/* Add button in product loop */
add_action('woocommerce_after_shop_loop_item', 'woodmart_add_quick_button_on_all_products', 15);

/* Enable for WooCommerce shortcodes */
add_filter('woocommerce_shortcode_products_loop', function( $content ) {
    add_action('woocommerce_after_shop_loop_item', 'woodmart_add_quick_button_on_all_products', 15);
    return $content;
});


/* ==============================
   Quick Shop Button CSS
============================== */
add_action('wp_head', function () {
?>
<style>
.quick-shop-button {
	
        font-size: 13px;         /* small font */
        line-height: 1;          /* line height fix */
        height: auto;            /* height auto */
        display: inline-flex;    /* flexbox for centering */
        align-items: center;     /* vertical center */
        justify-content: center; /* horizontal center */
    background-color: transparent !important;
    color: #000000 !important;
    padding: 10px 18px;
    
    font-weight: 600;
    border: 1px solid #000000;
    border-radius: 12px;
    
    margin-top: 8px;
    text-align: center;
    transition: all 0.3s ease;
}

.quick-shop-button:hover {
    background-color: transparent !important;
    border-color: #FF005E !important;
    color: #FF005E !important;
}

/* ==============================
   Mobile Responsive
============================== */
@media only screen and (max-width: 767px) {
    padding: 4px 10px;       /* compact padding */
        font-size: 8px;         /* small font */
        line-height: 1;          /* line height fix */
        height: auto;            /* height auto */
        display: inline-flex;    /* flexbox for centering */
        align-items: center;     /* vertical center */
        justify-content: center; /* horizontal center */
    }
}
</style>
<?php
});

