0

I have created a custom function to display 2 custom fields (ACF) and the price of the product after the item in the WooCommerce Archive/Shop page.

My Custom fields are show, but I am unable to get the WooCommerce price. How can I fix my function to show the price?

    add_action( 'woocommerce_after_shop_loop_item', 'acf_template_loop_product_meta', 20 );
function acf_template_loop_product_meta() {
    global $product;

    if ( $brand  = get_field('brand', $product->get_id()) ) {
        echo '<p><strong>'. __("&nbsp;&nbsp;&nbsp;&nbsp") . '</strong> ' . $brand . '</p>';
    }

    if ( $designer  = get_field('designer', $product->get_id()) ) {
        echo '<p><strong>'. __("&nbsp;&nbsp;&nbsp;&nbsp") . '</strong> ' . $designer . '</p>';
    }
    if ( $price = $product->get_price(); ) {
        echo '<p><strong>'. __("&nbsp;&nbsp;&nbsp;&nbsp") . '</strong> ' . $price . '</p>';
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.