Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1427270

    Hi
    I am trying to add some text above my products in woocommerce. I’d like it to show the category of the product.
    I have this code that adds the text, but I don’t know how to pull the category of the product:

    add_action( 'woocommerce_before_single_product_summary', 'enfold_customization_woocommerce_extra_text', 1);
    function enfold_customization_woocommerce_extra_text(){
    echo 'category goes here';
    }

    I have a checkout page with the checkout field labels used as placeholders, but I would rather have them above the input fields. I inherited this site and it seems that isn’t the default layout since I can find the code to use them as placeholders but not to move them above the fields.

    can you help me with this?
    thanks
    Nancy

    • This topic was modified 7 months, 3 weeks ago by Munford.
    #1427292

    Hi Munford,

    Please try to use this code instead:

    add_action( 'woocommerce_before_single_product_summary', 'enfold_customization_woocommerce_extra_text', 1);
    
    function enfold_customization_woocommerce_extra_text() {
        // Get the product categories
        $product_categories = get_the_terms(get_the_ID(), 'product_cat');
    
        // Check if there are categories
        if ($product_categories && !is_wp_error($product_categories)) {
            $category = reset($product_categories);
            echo '<p>Category: ' . esc_html($category->name) . '</p>';
        }
    }

    Hope it helps.

    Best regards,
    Nikko

    #1427313

    thanks!
    That gave me the text “Category: Beni Ouarain” (for example) above the photo.
    I removed the “Category” text since I just want the category name, but I need to move it above the title.
    Can that be done?

    If I use this code:

    add_action( 'woocommerce_before_single_product_summary', 'enfold_customization_woocommerce_extra_text', 1);
    function enfold_customization_woocommerce_extra_text(){
    echo 'category goes here';

    it puts the text above the title which is what I want but your code puts it above the photo.

    Aso: Any suggestions for the checkout field labels?

    best
    Nancy

    • This reply was modified 7 months, 3 weeks ago by Munford.
    • This reply was modified 7 months, 3 weeks ago by Munford.
    #1427387

    Hi Nancy,

    Please try to change the hook from woocommerce_before_single_product_summary to woocommerce_single_product_summary

    Then add this CSS code in Enfold > General Styling > Quick CSS:

    .single-product-summary .product_title {
        margin-top: 0;
    }

    Hope it helps.

    Best regards,
    Nikko

    #1427422

    fantastic! it worked perfectly.
    thanks so much!

    #1427440

    Hi,
    Glad Nikko was able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘code for woocommerce categories & checkout field labels’ is closed to new replies.