Search
 
SCRIPT & CODE EXAMPLE
 

PHP

woocommerce_variation_option_name on frontend

add_filter( 'woocommerce_variation_option_name','display_price_in_variation_option_name');

function display_price_in_variation_option_name( $term ) {
    global $product;

    if ( empty( $term ) ) {
        return $term;
    }
    if ( empty( $product->id ) ) {
        return $term;
    }

    $variation_id = $product->get_children();

    foreach ( $variation_id as $id ) {
        $_product       = new WC_Product_Variation( $id );
        $variation_data = $_product->get_variation_attributes();

        foreach ( $variation_data as $key => $data ) {

            if ( $data == $term ) {
                $html  = wp_kses( woocommerce_price( $_product->get_price() ), array() );
                $html .= ' - ' . $term;
                $html .= ( $_product->get_stock_quantity() ) ? ' - ' . $_product->get_stock_quantity() : '';
                return $html;
            }
        }
    }

    return $term;

}
Comment

woocommerce_variation_option_name on frontend

add_filter( 'woocommerce_variation_option_name','display_price_in_variation_option_name');

function display_price_in_variation_option_name( $term ) {
global $product;

if ( empty( $term ) ) {
    return $term;
}
if ( empty( $product->id ) ) {
    return $term;
}

$variation_id = $product->get_children();


foreach ( $variation_id as $id ) {
    $_product       = new WC_Product_Variation( $id );
    $variation_data = $_product->get_variation_attributes();
    $stock_status = $_product->get_stock_status();
    $stock_status = str_replace( array('instock','outofstock','onbackorder'), array('In Stock','Out of Stock','Please allow a few extra days for delivery'), $stock_status );

    foreach ( $variation_data as $key => $data ) {

        if ( $data == $term ) {
            $html  = wp_kses( woocommerce_price( $_product->get_price() ), array() );
            $html .= ' - ' . $term;
            $html .= ( $stock_status ) ? ' - ' . $stock_status : '';
            return $html;
        }
    }
}

return $term;

}
Comment

PREVIOUS NEXT
Code Example
Php :: find substring php 
Php :: laravel custom exception handler 
Php :: how to install apache mysql php on ubuntu 18.04 
Php :: Program for factorial of a number in php 
Php :: php library to convert html to amp 
Php :: wordpress query get results 
Php :: how to fetch the sum of column in php mysql 
Php :: Predefined Constants php 
Php :: set cookie on button click php or js 
Php :: laravel pagination with search filter 
Php :: laravel pivot table model 
Php :: update url wordpress 
Php :: how to get the size of an uploaded file in laravel 
Php :: eloquent insert into select 
Php :: php get array key 
Php :: create new record via model in laravel 
Php :: laravel migration type to store html 
Php :: php pdo like 
Php :: php str starts with 
Php :: language_attributes for wordpress 
Php :: How to Get Radio Button Value in PHP Without Submit 
Php :: check if column has value in laravel eloquent 
Php :: license_verify 
Php :: php thread safe or non thread safe 
Php :: append single quote around variable in php string 
Php :: wp large medium large 
Php :: laravel eloquent get x number of results 
Php :: PHP Parses a time string according to a specified format 
Php :: woocommerce recipient email default change Function 
Php :: how to back the page laravel where the scorll is 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =