Anyone able to provide a function.php snippet for Woocommerce Product field hooks in order to relocate an image swatch?

29 views Asked by At

I've been at this for a few days now and haven't had any luck with a snippet that works. I'm working on my wordpress site with elementor and advanced product fields pro for woocommerce. Ive managed to integrate all of my custom selection fields to my site but changing the position of the swatch has proven to be difficult. Im trying to relocate it so that it's posted below the product image instead of before_add_to_cart but none of the snippets I've found are working via the snippet . Can anyone help with this? Thanks in advance

`
// Remove the custom field from its current location before the Add to Cart button
remove_action('woocommerce_before_add_to_cart_button', 'display_fbg_gelcoat_custom_field');

    // Add the custom field below the product main image
add_action('woocommerce_before_single_product_summary','display_fbg_gelcoat_custom_field', 20);

    function display_fbg_gelcoat_custom_field() {
    global $product;
    // Fetch the custom field value using the meta key
    $fbg_gelcoat_value = get_post_meta($product->get_id(), 'fbg-gelcoat', true);
    if (!empty($fbg_gelcoat_value)) {
        echo '<div class="fbg-gelcoat-field-wrapper" style="margin-bottom: 20px;">' . esc_html($fbg_gelcoat_value) . '</div>';
    }
}
`

Custom field type is label ed as fbg-gelcoat but I've tried that, gelcoat, GelCoat (swatch name), and fbg_gelcoat as noted in the snippet and even though its shown on page, nothing has worked so far for changing positions.

0

There are 0 answers