-1

On my WooCommerce website I have fabric set to be sold per half meter, with the code below which is all working fine:

function conditional_price_suffix( $price, $product ) {

    $product_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();

    $product_categories = array('half-metre');

    if( has_product_categories( $product_categories, $product_id ) )
        $price .= ' ' . __('per ½ metre');

    return $price;
}

However, how do I manipulate the code to add another option of per "quarter-metre" and output "per ¼ meter" as the suffix.

Any help?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

0

could be something like

function conditional_price_suffix( $price, $product ) {
    $product_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();
    $product_categories = array('half-metre');
    $product_categories2 = array('quarter-metre');
    if( has_product_categories( $product_categories, $product_id ) ) {
        $price .= ' ' . __('per ½ metre');
    } elseif( has_product_categories( $product_categories2, $product_id ) ) {
        $price .= ' ' . __('per ¼ metre');
    }
    return $price;
}
Andrei Filonov
  • 814
  • 6
  • 8