Support

Account

Home Forums Search Search Results for 'woocommerce'

Search Results for 'woocommerce'

reply

  • That’s great, thanks so much for checking.

    I’m going to run the same tests on another test server I have just to rule out anything odd like Redis caching the old values or something. I’ve had strange things with Redis caching db queries in WooCommerce when they were stored in the options table. My cloned base fields are in Options too.

    I’ll file a bug later / tomorrow and keep you posted. 🙂

  • Why do you want to use ACF to duplicate this info? WooCommerce stores that data in meta key/value pairs already. For instance, you can access length with something like:

    <?php echo get_post_meta($post->ID, '_length', true); ?>

  • You need to look into documentation and help from WooCommerce for doing this. Doing what you want with ACF would not be much different than doing this with standard WP custom meta fields.

  • You need to supply ACF with the post ID, in this case that is the product ID.

    https://stackoverflow.com/questions/27385920/woocommerce-get-current-product-id

    
    add_action('woocommerce_shop_loop_item_title', 'custom_pre_title');
    function custom_pre_title(){
      global $product;
      $id = $product->get_id();
      $field_value = get_field('field_name', $id);
    }
    
  • Something like this, but the syntax is not correct:

    add_action('woocommerce_shop_loop_item_title', 'custom_pre_title');
    function custom_pre_title(){
    if ((is_product_category() && get_field('product_attribute_1')) {
    	<div class="styling"><?get the_field('product_attribute_1'); ?></div>
  • ok, adding at the end:
    add_action(‘woocommerce_update_product’, ‘perf_pln2’);
    solved the issue 🙂

  • @justin-graham I cannot provide hands on help. For that you would need to open a ticket by logging into your account. Not sure if the new devs provide that type of support or not.

    I would try changing your add_action() to include the variables provided by WC

    
    add_action('woocommerce_single_product_summary', 
                  'woo_display_custom_general_fields_values', 45, 2);
    function woo_display_custom_general_fields_values($post, $product) {
      .........
    

    and then supply ACF with the post ID in get field

    
    // example
    $parentSKU = get_field('parent_barcode_sku', $post->ID);
    

    If that does not work I would look in the database and make sure that WPAI is creating the correct field key references and storing the value correctly. If it is not then the issue is with WPAI.

  • This reply has been marked as private.
  • I am having the same issue.

    WP: 6.1.1
    WOO: 7.3.0
    PHP: 7.4.33
    ACF: 6.0.7

    I have imported all produces via CSV using WP-All-IMPORT

    The ACF value are populated and saved in the WooCommerce Product.
    This is evident when navigating to EDIT PRODUCT

    However the [value] [label] or [array] is not being out on the front end until the post has been [updated]

    2000 products – I’m not updating manually.

    ACF Button Group
    Choices
    value : Label
    value : Label
    value : Label

    returning value : (•) Label

    I have tried get_field && get_field_object (using array)

    value won’t return until the post is updated

    John – I can provide access to the site if needed

  • Ok, I understand the “technical” reason but I still think it would be great to have this feauture, at least for PRO users. And it’s true that ACF does not need to support every 3rd party plugin, but maybe it should fully support at least the “bigger ones” like WooCommerce.

  • Sorry, but I do not understand your logic.

    WooCommerce IS a 3rd party plugin and ACF does supports WooCommerce (products and orders), right? So, ACF already supports 3rd party plugin like WooCommerce.

    But it doesn’t fully support because some things are missing, like ACF for specific product variations. And that’s the purpose of the feature request.

    In my opinion, it would be a nice addition 🙂

  • Its work for me

    add_filter('posts_clauses', 'sem_order_by_stock_status');
    function sem_order_by_stock_status($posts_clauses) {
        global $wpdb;
        // only change query on WooCommerce loops when ACF fields are not requested in the WHERE statement
        if (!is_acf_request($posts_clauses['where']) && is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
            $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
            $posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
            $posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
        }
        return $posts_clauses;
    }
    
    function is_acf_request($text){
    	if (strpos($text, 'acf-field'))
    		return true;
    	return false;
    }
  • Your filter on the hook posts_clauses affects every query that is done, in this case it will happen on any page load where this is true

    
    if ( is_woocommerce() && ( is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy() ) ) {
    

    and this will effect ACF queries to get values of fields.

    I cannot tell you how to correct this, when I’m altering a WP query I generally do this by using a pre_get_posts action and for example if I want to change the orderby value I do it by altering the main query, not by adding clauses to the query.

  • That custom fields UI inside of WooCommerce is not part of the standard ACF plugin or the Pro plugin. Also, the field types are not field types that are offered by ACF or ACF Pro. These are from another plugin. Are you using ACF Extended? For support on that plugin you need to contact the developer of that plugin.

  • They are called hooks, not really a PHP thing, it’s a WP thing.

    Search for WooCommerce Visual Hooks

    Also see https://woocommerce.github.io/code-reference/hooks/hooks.html

  • Just a quick follow-up question, so I understand how to use this concept where ever I need to:

    How do I best to apply this to other page types, eg. single product page, blog archive, blog page, etc. Is there a list of phrases/descriptors I can swap out for ‘woocommerce_before_shop_loop_item_title’? I apologize, I know very little PHP; if I knew what to call these descriptors I could look it up… Your answers have me interested in learning more about these possibilities.

    For example, on a single product page, is there anything wrong coding-wise with the this?:

    
    // Try it on the single product page
    
    add_action('woocommerce_before_shop_loop_item_title', 'custom_single_product_css');
    function custom_single_product_css() {
      global $product;
      ?>
        <style type="text/css">
          .my-custom-block-class {
            background: url(<?php the_field('my_image', $product->id); ?>);
    }
        </style>
      <?php 
    }
    
  • 
    add_action('woocommerce_before_shop_loop_item_title', 'custom_product_css');
    function custom_product_css() {
      global $product;
      ?>
        <style type="text/css">
          .woocommerce .products .grid-common-col.post-<?php echo $product->id; ?> {
            background-image: url(<?php the_field('my_image', $product->id); ?>);
          }
        </style>
      <?php 
    }
    
  • I am assuming that post-32 refers to the post ID of the product. But, the classes you are using for targeting do not match those used in a standard WC product loop, so I could be completely wrong, but that could have something to do with the theme I’m looking at.

    
    add_action('woocommerce_before_shop_loop_item_title', 'custom_product_css');
    function custom_product_css() {
      global $product;
      ?>
        <style type="text/css">
          .woocommerce .products .grid-common-col.post-<?php echo $product->id {
            background-image: url(<?php the_field('my_image', $product->id); ?>);
          }
        </style>
      <?php 
    }
    
  • Hi bentangible!

    Thanks for the fast reply! Yes i made a custom product loop skin for my site. Maybe i should be more specific about the thing i want to achieve with ACF.

    So as default woocommerce has a thumbnail upload option for the core Categories taxonomy, but not for tags or custom taxonomies: Image

    This image can be pulled dynamically by elementor under the Dynmic tags-> Woocommerce-> Category Image as shown: Image

    I want to replicate this dynamic image function from woocommerce, so i created a custom taxonomy for brands, to display the brand logo on the frontend. With ACF i added an image upload field for the taxonomy: Image

    So right now i am able to upload an image for each brand in the taxonomy, and i can select the image field in elementor: Image

    But after i select the acf image field, the logo doesnt show up on the frontend.

    Im a bit confused, maybe im missing some code that outputs this image field on the front end.

  • Hi Vinit. How did you solve this? How did u setup the reminder email, for example set reminder 3 days before the acf date on woocommerce? Any guidance will be appreciated.

  • Thank you for information, i have more questions now:
    How i can querry and loop over all woocommerce products in functions.php?

    I created cronjob, made it run one time per day:

    
    add_action( 'triname_datas', 'triname_datas_func' );
    function triname_datas_func() {
      $today = date('Y-m-d');
      $repeater = get_field('pasirinkti_datas');
    // $repeater is an array of rows
    $count = count($repeater);
    for ($row=$count; $row>0; $row--) {
      if (get_sub_field('keliones_datos', $repeater) >= $today) {
        delete_row('pasirinkti_datas', $row);
      }
    }
    }
    

    But it is not working, i need to query and loop through products.

  • Hi, still experiencing this issue but with some more background to it, this is found in our products-page.php

    {% extends "base.twig" %}
    {% block main %}
    {% if products %}
        <div class="shop-page-wrapper" data-bg="{{ shop_color}}">
            {# <nav class="categories">
                {% include 'partials/filters-nav.twig' %}
            </nav> #}
            <div class="products">
                {% for post in products %}
                    {{ fn('timber_set_product', post) }}
                   {% set hover = function('get_field', 'hover_image', post.id ) %}
                    <a href="{{ post.link }}"  class="product {{ post.class ~ ' width-' ~ width_in_shop }}">
                        <div class="product-img-wrapper">
                            <img class="" src="{{ post.thumbnail.src('shop_catalog') }}"/>
                            <img class="" src="{{ hover.sizes.shop_catalog }}"/>
                        </div>
                        <div class="product-info">
                            <h3 class="woocommerce-loop-product__title">{{ post.post_title }}</h3>
                            <div>{% do action('woocommerce_after_shop_loop_item_title') %}</div>
                        </div>
  • I am looking for some assistance with the following:

    Currently I have a custom function setup to display my ACF field “start_date_dont_edit” as a column on my backend Orders dashboard in Woocommerce. The column shows, allows sorting, and displays my date field values perfectly. However, it is not sorting correctly by date in either direction. It just seems kind of random.

    Hoping someone might be able to have a look and see what I am missing or did wrong, in order to get the column to sort by date (oldest to newest and vice versa) when clicking on the sortable column.

    Thanks!

    // Order column - Add ACF Start Date to Admin view
    function webroom_add_order_new_column_header( $columns ) {
    
        $new_columns = array();
    
        foreach ( $columns as $column_name => $column_info ) {
    
            $new_columns[ $column_name ] = $column_info;
    
            if ( 'order_total' === $column_name ) {
                $new_columns['order_details'] = __( 'ACF Start', 'acf-start' );
            }
        }
    
        return $new_columns;
    }
    add_filter( 'manage_edit-shop_order_columns', 'webroom_add_order_new_column_header', 20);
    
    /* Add data in column to sort */
    add_action( 'manage_shop_order_posts_custom_column', 'webroom_add_wc_order_admin_list_column_content' );
     
    function webroom_add_wc_order_admin_list_column_content( $column ) {
       
        global $post;
     
        if ( 'order_details' === $column ) {
     
            $order = wc_get_order( $post->ID );
    		$thisacof6 = get_post_meta( $order->get_id(), 'start_date_dont_edit', true );
    		$new_startdate = date_format(date_create_from_format('Y-m-d', $thisacof6),'m-d-y');
            echo $new_startdate;
          
        }
    }
    
    // Make custom column sortable ** Need help figuring out how to get the column to sort by date
    add_filter( "manage_edit-shop_order_sortable_columns", 'shop_order_column_meta_field_sortable' );
    function shop_order_column_meta_field_sortable( $columns )
    {
        $meta_key = 'start_date_dont_edit';
        return wp_parse_args( array('order_details' => $meta_key), $columns );
    }
    
    // Make sorting work properly (by numerical values)
    add_action('pre_get_posts', 'shop_order_column_meta_field_sortable_orderby' );
    function shop_order_column_meta_field_sortable_orderby( $query ) {
        global $pagenow;
    
        if ( 'edit.php' === $pagenow && isset($_GET['post_type']) && 'shop_order' === $_GET['post_type'] ){
    
            $orderby  = $query->get( 'orderby');
            $meta_key = 'start_date_dont_edit';
    
            if ('start_date_dont_edit' === $orderby){
              $query->set('meta_key', $meta_key);
              $query->set('orderby', 'meta_value_num');
            }
        }
    }
  • Hi Milena,

    you also of course need to adapt your woocommerce templates to output the custom fields.
    Start with creating a child theme and identify the template or template part you want to edit.
    then read the developer docs about how to adapt the templates with a child theme: https://woocommerce.com/document/template-structure/

Viewing 25 results - 376 through 400 (of 889 total)