Support

Account

Home Forums Search Search Results for 'woocommerce'

Search Results for 'woocommerce'

reply

  • It seems that there are no such filters. I put a clean version of WordPress on a test site. Installed plugins – Woocommerce, ACF and ACF for WooCommerce. Created custom fields and placed them in the my-account of the user WooCommerce.

    In the database, the fields are still stored as field_5ba168bfdcb58 (user_phone) and field_5ba16910dcb59 (user_age). Therefore, I no longer know what to do.

  • As it turned out, this plugin “ACF for Woocommerce” saves the field data as meta_key: “field_5b7e4f388fd11” and meta_value: “+79998006655”. Tell me how to correctly display the fields in my code?

    get_field( 'field_5b7e4f388fd11', "user_{$user_id}" )

    This for some reason does not work. Emails come empty fields ((

  • Thanks again for your help on this, John. I didn’t get it working in the end and instead reverted to using WooCommerce hooks to append fields to the registration form.

    I’ve not ruled out revisiting your proposed solution at a later date though as I’m using an ACF form on the user’s account page and would ideally like to be using the same one on the register form, rather than maintaining two sets of fields. If I do eventually get it to work I’ll update this thread with my results.

  • If not use the “ACF for WooCommerce” plugin, then how do put custom fields in my account page of WooCommerce?

  • Whoa – after more testing, I found the validation error only happens if I try to change the parent page. I can edit other fields on the page and it validates as I expect it to.

    I also found the same issue on another site on a WooCommerce product. The validation error happens on a required, but hidden and empty WYSIWYG field, and only when changing the Product Category. I can make changes to other fields and the product validates, even with the hidden, empty, required field.

  • I found a possibly unstable solution but it seems to work so far without any kind of notices or errors ( as of yet ). It takes advantage of both the relationship query hook to set a specific flag and the posts_clauses hook to join the postmeta table and search on that. The SQL solution was found via Iconic WP blog post of a similar nature.

    /**
     * Product relationship field - include searching SKU
     * 
     * @param Array $args
     * @param Array $field
     * @param Integer $post_id
     * 
     * @return $args 
     */
    function prefix_product_relationship_query_mods( $args, $field, $post_id ) {
    
    	$args['post_status'] = 'publish';
    
    	if( ! empty( $args['s'] ) ) {
    		$args['acf_sku_search'] = true;
    	}
    
    	return $args;
    
    }
    add_filter( 'acf/fields/relationship/query/name=field_name', 'prefix_product_relationship_query_mods', 10, 3 );
    
    /**
     * Modify the query clauses to search on the postmeta table when asked to :)
     *
     * @param Array $clauses
     * @param WP_Query $query
     *
     * @return Array $clauses
     */
    function prefix_acf_relationship_search_sku( $clauses, $query ) {
    
    	global $wpdb;
    
    	if( $query->get( 'acf_sku_search', false ) ) {
    
    		$clauses['join'] 	= " LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ";
    		$clauses['where'] 	= preg_replace(
    			"/\(\s*{$wpdb->posts}.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
    			"({$wpdb->posts}.post_title LIKE $1) OR ({$wpdb->postmeta}.meta_key = '_sku' AND {$wpdb->postmeta}.meta_value LIKE $1)",
    			$clauses['where']
    		);
    		$query->set( 'acf_sku_search', false );	// Set to false just in case.
    
    	}
    
    	return $clauses;
    
    }
    add_filter( 'posts_clauses', 'prefix_acf_relationship_search_sku', 10, 2 );
  • Thanks very much for your help. Your explanation helped me to understand how hooks work.

    It’s actually on the archive page I want to add the ACF so in content-product.php using ‘woocommerce_after_shop_loop_item_title’ should have worked, but my theme (Astra) also seems to be influencing that area, so in the end I hid the title using the theme customiser and then in functions.php

    /**
     * ADD THE ACF DESCRIPTOR BY REMOVING THE FUNCTION AND REPLACING IT WITH OUR OWN - YOU MUST ALSO HIDE THE TITLE IN ASTRA CUSTOMISER
     */
    function sly_switch_loop_title(){
        remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
        add_action( 'woocommerce_after_shop_loop_item_title', 'sly_template_loop_product_title', 15 );
    }
    add_action( 'woocommerce_before_shop_loop_item', 'sly_switch_loop_title' );
    
    function sly_template_loop_product_title() {
        echo '<h4 class="sly-custom-shop-list-title">' . get_the_title() . '</h4>';
    	echo get_field( 'descriptor' );
    }
  • WooCommerce has _a literal ton_ of hooks to use. If you open up the plugin folder ( plugins/woocommerce/templates ) you can open up those files and see just how many you can hook into.

    The one you’re looking for is in the content-single-product.php file:

    /**
     * Display value after single product titles
     *
     * @return void
     */
    function prefix_after_title() {
    	echo get_field( 'after_title' );
    }
    add_action( 'woocommerce_single_product_summary', 'prefix_after_title', 6 );

    We need the priority of 6 because the file linked above shows that the title is prioritized at 5. If we wanted to display this before the title we would need to change the priority to something before 5.

  • Same here. I haven’t found a solution yet.

    Looks like I’ll have to add it manually. It would be pretty powerful though, to add ACF fields to any WooCommerce email template easily.

  • Yea sure no problem. I have created several categories with woocommerce. And i linked them with ACF like this:
    https://i.imgur.com/k4p1Q7J.png

    However when i go to one of these cats, i don’t see the extra fields, i have saved the post like you said. Also at the bottom of the category page there is nothing, it does show some general fields i added to the woocommerce categories with these settings:
    https://i.imgur.com/oTzI5rm.png

    However these are general fields i need to fill. Those categories are different from the rest and need some additional fields.

    Hope i clarified it enough, otherwise just let me know 🙂

  • I understood. Do you use the ACF for WooCommerce plugin? This can be a problem with the ACF for WooCommerce plugin?

    I need to show custom fields in the WooCommerce account and send user data by email.

  • I got it working using the Wysiwyg Editor to upload the image instead. Thanks for your help.

    The final code is

    add_action('woocommerce_single_product_summary','finish_image',22);
    
    function finish_image() {
    
    $terms = get_the_terms( $post->ID , 'pa_metal-finish' );
    if($terms) {
       foreach( $terms as $term ) {
    
      echo '<b>Finish: </b>'. get_field('finish_img', 'pa_metal-finish'.'_'.$term->term_id);
    
    }
    }
    }
    

    With use of the Wysiwyg Editor for image upload

  • Sorry I just realized I should have added it as a code

    add_action('woocommerce_single_product_summary',"finish_image",22);
    
    function finish_image() {
    
    $terms = get_the_terms( $post->ID , 'pa_metal-finish' );
    if($terms) {
       foreach( $terms as $term ) {
    
      echo '<b>Finish:</b>'. '<img src= '<?php get_field('finish_img', 'pa_metal-finish'. '_' .$term->term_id);' ?>' />'
    }
    }
    }
    	
    	
  • I am so close, keep coming up with a parce error. What am I doing wrong here? I know it has something to do with the IMG SRC and quotes

    add_action(‘woocommerce_single_product_summary’,”finish_image”,22);

    function finish_image() {

    $terms = get_the_terms( $post->ID , ‘pa_metal-finish’ );
    if($terms) {
    foreach( $terms as $term ) {

    echo ‘<b>Finish:</b>’. ‘term_id);’ ?>’ />’
    }
    }
    }

  • Making progress I know have the code working, only shows url still though. need to look though the document above

    add_action(‘woocommerce_single_product_summary’,”finish_image”,22);

    function finish_image() {

    $terms = get_the_terms( $post->ID , ‘pa_metal-finish’ );
    if($terms) {
    foreach( $terms as $term ) {

    echo ‘<b>Finish:</b>’. get_field(‘finish_img’, ‘pa_metal-finish’. ‘_’ .$term->term_id);
    }
    }
    }

    I am close though

  • I have gotten the image url to show back up if I give the full path to a single Attribute.

    add_action(‘woocommerce_single_product_summary’,”finish_image”,22);

    function finish_image() {
    echo ‘<b>Finish:</b>’. get_field(‘finish_img’, ‘pa_metal-finish_79’);
    }

    But I need the code to search though the metal finish attributes to find the one that applies to that Item.

    I know its something like the post found here.

    https://support.advancedcustomfields.com/forums/topic/get-field-from-woocommerce-attribute-taxonomy/

    but I cant seem to quite figure it out, do you have any insite?

  • Well I have done some research and have almost got the code working. Currently the code looks like this

    add_action(‘woocommerce_single_product_summary’,”finish_image”,22);

    function finish_image() {
    echo ‘<b>Finish:</b>’ .get_field(‘finish_img’, $product_id);
    }

    For some reason the image will not show, It just shows the text “array”(not the setting the actual word array). If I change it to URL, It shows the right url and if I change it to Image ID it show the right id.

    After playing with the settings more, I can no longer get anything to come up, please help!

    Thanks

    Jake

  • When working with WC you more than likely need to use one of their action hooks to show the field where you want it shown on the product page. https://docs.woocommerce.com/wc-apidocs/hook-docs.html

    In your action you need to get/show the value by passing ACF the product ID (Post ID), example: get_field('your-field-name', $product_id);

    Some of the action hooks pass the product ID and in other cases you’ll need to figure out how to get the ID.

  • Sooooo…y’all were super helpful before and I was able to apply this filtering to another website as well. All was going swimmingly until the client asked for one more level of sorting, and I’m tearing my hair out trying to figure this out.

    So, this is for a choral group. They’re wanting to display all their past seasons, sorted by year/season, and then by performance date (performances are actually individual products in WooCommerce). Sorting by the ACF meta fields is going fine. But within each year, they also want to break it out to sorting all the concerts assigned the ‘cantata-series’ product category, and the ‘masterworks-series’ product category. So, a typical listing would look something like:

    2017-2018 SEASON
    Cantata Series
    * Concert Date 1
    * Concert Date 2
    Masterworks Series
    * Concert Date 1
    * Concert Date 2

    2016-2017 SEASON
    Cantata Series
    * Concert Date 1
    * Concert Date 2
    Masterworks Series
    * Concert Date 1
    * Concert Date 2

    etc. etc. etc.

    I was doing fine when it was just sorting by season and then by date. But adding in sorting by category is just throwing me. I can get it to display the correct series before each and every date it applies to, but that’s not right.

    Here’s my code right now (not working)

    $season_args = array(
    		'numberposts' => -1,
    		'post_type' => 'product',
    		'product_cat' => 'past, cantata-series, masterworks-series',
    		'meta_query' => array(
    			'season_clause' => array(
    				'key' => 'select_season',
    				'compare' => 'EXISTS',
    			),
    			'date_clause' => array(
    				'key' => 'date',
    				'compare' => 'EXISTS',
    			)
    		),
    		'orderby' => array(
    			'season_clause' => 'ASC',
    			'date_clause' => 'ASC'
    		)
    	);
    	
    	$the_query = new WP_Query($season_args);
    	
    	if ($the_query->have_posts()) {
    		// variables to hold values from previous post
    		$last_season = '';
    		$last_date = '';
    		
    		while ($the_query->have_posts()) {
    			$the_query->the_post();
    			
    			// get season and compare it to the previous post
    			$this_season = get_field('select_season');
    			
    			if ($this_season != $last_season) {
    				// the season has changed
    				if ($last_season != '') {
    					// close the post UL, season DIV, and season DIV that we'll open next
    					// this will be skipped if this is the first post
    					// because $last_season will be empty
    					echo '</div><!-- .season -->';
    				} ?>
    				
    				<div class="season">
    					<h2><?php echo $this_season->post_title; ?></h2>
    				
    				<?php  // clear $last_season
    				$last_season = '';
    				// set $last_season to $this_season
    				$last_season = $this_season; ?>
    				
    				<?php if ( has_term( 'cantata-series', 'product_cat' ) ) { ?>
    						<h3>Cantata Series</h3>
    						
    				<?php } 
    			} // end if new season
    			
    			// get the date and compare to previous post
    			$this_date = get_field('date', false, false);
    			$this_date = new DateTime($this_date); ?>
    			
    				
    							<?php if ( has_term( 'cantata-series', 'product_cat' ) ) { ?>
    							<li><?php echo $this_date->format('M j Y'); ?> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php } ?>
    		<?php } // end while have posts
    	} // end if have_posts
    
    wp_reset_query();

    Thanks in advance.

    ~Laura

  • Here is the action and filter I’m using to show on product page and the cart:

    function save_my_custom_product_field( $cart_item_data, $product_id ) {
    
        $custom_field_value = get_field( 'install_fee', $product_id, true );
    
        if( !empty( $custom_field_value ) ) 
        {
            $cart_item_data['install_fee'] = $custom_field_value;
    
            // below statement make sure every add to cart action as unique line item
            $cart_item_data['unique_key'] = md5( microtime().rand() );
        }
        return $cart_item_data;
    }
    
    add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart', 10, 2 );
    
    function render_meta_on_cart( $cart_data, $cart_item ) {
        $custom_items = array();
        // Woo 2.4.2 updates
        if( !empty( $cart_data ) ) {
            $custom_items = $cart_data;
        }
        if( isset( $cart_item['install_fee'] ) ) {
            $custom_items[] = array( "name" => "Install Fee $", "value" => $cart_item['install_fee'] );
        }
        return $custom_items;
    }
    
  • This reply has been marked as private.
  • If the field group did not exist before the import then you can’t make these fields appear by creating a new field group.

    And it appears that the fields were not imported to the taxonomy/terms but were imported to the posts. This is why the values do not appear when editing the product category. Since these values are not associated with the term you cannot make them appear in the admin. Quite honestly, I don’t know how they are appearing in the front end.

    Importing into a term is a special process http://www.wpallimport.com/documentation/taxonomies/import-taxonomy-meta/

    in your code

    
    global $woocommerce, $woocommerce_loop, $product;
    $category = get_queried_object();
    $ct = $category->name;
    $catid = $category->term_id;
    the_field('description', $catid); ?>
    

    the value of $catid is wrong. In order to get a value from a field for the term it would need to be the_field('description', 'term_'.$catid); so what you are actually seeing on the front end is the values in post meta that are related to a post with the ID that is equal to whatever that the ID of the term is.

    There really isn’t an easy solution to this if there is a solution at all. If there is I can’t think of one.

  • Hi James, thanks for looking into this. On further investigation it seems to be a conflict with Woocommerce. The bug does not appear without Woocommerce installed and active, so the steps to reproduce are…

    1) install fresh WordPress
    2) install ACF Pro
    3) install Woocommerce
    4) add ACF wysiwyg field to pages
    5) add an embeddable youtube video URL to the wysiwyg field on a page (video appears)
    6) Save page

    Now when you navigate away you get “Changes you made may not be saved.”. Sometimes you have to click on the page (say, to close the ‘page updated’ message) to get the ‘unsaved changes’ message when navigating away, but other times it appears just by reloading via browser address bar.

    Disable woocomemrce and the problem goes away. Add the youtube URL to the main content rather than the ACF wysiwyg and the problem does not occur (this only occurs with auto embed URLs in the ACF wysiwyg).

Viewing 25 results - 651 through 675 (of 894 total)