Support

Account

Home Forums Search Search Results for 'woocommerce'

Search Results for 'woocommerce'

topic

  • Solving

    Update ACF field when WooCommerce subscription renews?

    Hey everyone,

    Does anyone know if it’s possible to update an ACF field whenever a WooCommerce subscription is renewed?

    I need a custom user field (a number field) to have 1 added every time a subscription renewal order is processed.

    The goal is to create a credit system where 1 credit is added every time a customer renews their membership subscription. However, the maximum amount of credits is 2. So if they already have 2 credits, another will not be added.

    Credits will be manually subtracted on the blackened when redeemed.

    Any ideas or pointers on how to get something like this going? Thanks!

  • Solved

    Wysiwyg Editor – hooks for "Add Media" button?

    I have a Wysiwyg Editor field, with media upload button enabled, and I would like to identify and target the AJAX queries coming from its media upload button (“Add Media”). Specifically, I’d like to 1) filter the shown attachments in the modal and 2) operate on the uploaded attachment.

    I have done something similar with Image upload fields, by following this solution: https://support.advancedcustomfields.com/forums/topic/filter-gallery-items/#post-41465

    Thus, for an Image field, I set up a filter for ajax_query_attachments_args and checked against the _acfuploader identifier with an if ($_POST['query']['_acfuploader'] == $THE_FIELD_ID) condition. Inside that condition I could then modify the AJAX query e.g. to show only attachments uploaded by the current user.

    Then, after submitting the form (for my very own use case it was appropriate to use the woocommerce_save_account_details hook), I simply got the attachment’s ID from the $_POST data using $_POST['acf'][$image_field_key] and could then modify that attachment.

    
    // (1) filter the shown attachments
    function restrict_current_user_to_own_attachments( $query = array() ) {
    
        // Allow requests only from users with access
        if ( ! current_user_can( 'upload_files' ) ) {
            wp_send_json_error();
        }
    
        // Only target the specific ACF field
        if ( $_POST['query']['_acfuploader'] == $THE_FIELD_ID ) {
    
            $user_id = get_current_user_id();
    
            if ( $user_id ) {
                // Query only attachments uploaded by the current user
                $query['author'] = $user_id;
            }
        }
        else if ( $_POST['action'] == 'query-attachments' && !current_user_can( 'administrator' ) ) {
    
            $user_id = get_current_user_id();
    
            if ( $user_id ) {
                $query['author'] = $user_id;
            }
    
        }
        else if ( $_POST['action'] == 'query-attachments' && current_user_can( 'administrator' ) ) {
    
            $user_id = get_current_user_id();
    
            // I could target a specific page, if I was unable to target the field.
            if ( strpos( $_SERVER[ 'HTTP_REFERER' ], "/${$MY_PAGE}" ) !== false && $user_id ) {
                //  manipulate AJAX query
            }
    
        }
    
        return $query;
    }
    // Filter wp uploader shown attachments using ajax_query_attachments_args
    add_filter( 'ajax_query_attachments_args', 'restrict_current_user_to_own_attachments', 10, 1 );
    
    // (2) operate on uploaded attachment
    function my_save_form( $user_id ) {
        if ( isset( $_POST['acf'][$THE_FIELD_ID] ) ) {
            // ...
            if ( is_user_logged_in() && current_user_can('upload_files') ) {
                $attachment_id = (int) $_POST['acf'][$THE_FIELD_ID];
                // Do stuff to the attachment
            }
        }
    }
    add_action( 'woocommerce_save_account_details', 'my_save_form', 10, 1 );

    The problem with the Wysiwyg Editor’s media upload button is that I couldn’t find anything identifiable about it, in order to be able to modify the AJAX query for that purpose. So I made a compromise and modified it for ordinary user roles and for more elevated users such as admins (current_user_can( 'administrator' )) I targeted the entire page instead of the field, using the $_SERVER['HTTP_REFERER'] (admins are trusted to not spoof the referer).

    However, I still need to operate on the attachments that were uploaded from that specific “Add Media” button, right after they were uploaded, and I’ve failed to find any hook where I could have both access to the attachment ID AND where the $_SERVER['HTTP_REFERER'] would point to the page of the ACF form. If anyone knows of any useful hook, it’d certainly save me plenty of more hours of trying.

  • Solved

    How to Nest File & Link ACF Get Field

    Hi,

    I started with an ACF File Field to display the relevant product file in our Single Product pages in WooCommerce. However, in some cases the file is an atrocious size, so I’m looking to adapt my setup to incorporate an external Link (Google Drive, Dropbox etc.

    I’m unsure how to set up the context so that it only checks and outputs one field if both ever become available.

    For Example;

          if(ACF File === true && ACF Link === False){
             //Display file in href
         }
         if(ACF File === false && ACF Link === true){
             //Display link in href
          }
    }else{
        //run this else only when the first 2 IFs are false
         }
    }

    Any advice would be great.

    Thanks

  • Solving

    html custom field

    Hey I would like to add custom field to my products imported via woocommerce. Basically I would like to show google trend via html code example:

    <script type=”text/javascript” src=”https://ssl.gstatic.com/trends_nrtr/3045_RC01/embed_loader.js”></script&gt; <script type=”text/javascript”> trends.embed.renderExploreWidget(“TIMESERIES”, {“comparisonItem”:[{“keyword”:”lol”,”geo”:”PL”,”time”:”today 12-m”}],”category”:0,”property”:””}, {“exploreQuery”:”geo=PL&q=lol&date=today 12-m”,”guestPath”:”https://trends.google.pl:443/trends/embed/&#8221;}); </script>

    Every product will be different code that is why I would like to import it via custom field. However in elementor I can’t add html dynamic tag. Can you help with that?

  • Solving

    ACF plugin is causing "headers already send by…" error

    ACF plugin is causing “cannot modify header information – headers already send by (bla bla bla/public_html/wp-content/themes/bifrost/header.php:1)” in my file.
    The firsts 26 lines of my header.php:1 file show:

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    <meta charset=”<?php bloginfo(‘charset’); ?>”>
    <meta name=”viewport” content=”width=device-width, initial-scale=1″>
    <meta http-equiv=”X-UA-Compatible” content=”ie=edge”>
    <?php
    /**
    * Queried Object
    *
    * In case it is shop page get_queried_object won’t
    * work, it needs to be changed to a custom WooCommerce
    * function wc_get_page_id.
    */
    $bifrost_queried_object = class_exists(‘WooCommerce’) && is_shop() ? wc_get_page_id(‘shop’) : get_queried_object();

    /**
    * Redirect
    */
    if (get_field(‘general_redirect’, $bifrost_queried_object) && get_field(‘general_redirect_url’, $bifrost_queried_object)) {
    wp_redirect(get_field(‘general_redirect_url’, $bifrost_queried_object));
    exit;
    }

    wp_head();
    ?>

    I already:
    1 – checked for blank spaces
    2 – moved the <!DOCTYPE html> around
    3 – Installed an older version of ACF
    4 – and did a lot of other things suggested in previous post, but nothing worked so far.

    When I deactivate ACF plugin, my page work fine, but I loose all configuration made using the ACF plugin. Somehow, this same configuration is working fine in bermelloajamil.info, but after migrating this content to bermelloajamil.com, the error shows up. Can you guys help me?

  • Unread

    ACF on custom product tabs

    Hi,

    I’m trying to load ACF fields on custom product tabs, but without great success. The code I’m using, to create the tabs:

    function custom_product_tabs( $tabs) {
    
    	$tabs['section_nutritional'] = array(
    		'label'		=> __( 'Nutritional Declaration', 'woocommerce' ),
    		'target'	=> 'section_nutritional',
    		'class'		=> array( 'show_if_simple', 'show_if_variable'  ),
    	);
    
    	$tabs['section_directions'] = array(
    		'label'		=> __( 'Directions', 'woocommerce' ),
    		'target'	=> 'section_directions',
    		'class'		=> array( 'show_if_simple', 'show_if_variable'  ),
    	);
    
    	return $tabs;     
    
    }
    add_filter( 'woocommerce_product_data_tabs', 'custom_product_tabs' );

    I’m trying to load the ACF field like this:

    function woocommerce_product_section_nutritional()
    {
    	global $woocommerce, $post;
    	echo '<div id="section_nutritional" class="panel woocommerce_options_panel hidden">';
    	echo $variable = get_field('teste_texto_nutri');	
    
        woocommerce_wp_text_input(
    		array(
    			'id' => 'nutritional_table',
    			'placeholder' => 'Insert Table',
    			'label' => __('Test ACF', 'woocommerce'),
    			'desc_tip' => 'true',
                'value' => the_field('teste_texto_nutri')
    		)
    	);
    
        woocommerce_wp_textarea_input(
    		array(
    			'id' => 'nutritional_text',
    			'placeholder' => 'Insert Text',
    			'label' => __('Additional Text', 'woocommerce'),
    			'desc_tip' => 'true'
    		)
            
    	);
    }

    I’ve also tried to create a callback function in the definition of the new tabs, but without success.

    What I’m trying to do is possible? If yes, can anyone help me on how to do it?

  • Solved

    How to Display fields on frontend w snippet

    Hello all,

    I would like to ask help.

    I tried so many solutions but nothing work.

    I created a custom tab for WooCommerce (My Profile) name as “Üzleteim”, with CodeSnippets.

    Here is the code:

    add_action( 'init', 'register_uzleteim_endpoint');
    
    /**
     * Register New Endpoint.
     *
     * @return void.
     */
    function register_uzleteim_endpoint() {
    	add_rewrite_endpoint( 'uzleteim', EP_ROOT | EP_PAGES );
    }
    
    add_filter( 'query_vars', 'uzleteim_query_vars' );
    
    /**
     * Add new query var.
     *
     * @param array $vars vars.
     *
     * @return array An array of items.
     */
    function uzleteim_query_vars( $vars ) {
    
    	$vars[] = 'uzleteim';
    	return $vars;
    }
    
    add_filter( 'woocommerce_account_menu_items', 'add_uzleteim_tab' );
    
    /**
     * Add New tab in my account page.
     *
     * @param array $items myaccount Items.
     *
     * @return array Items including New tab.
     */
    function add_uzleteim_tab( $items ) {
    
    	$items['uzleteim'] = 'Üzleteim';
    	return $items;
    }
    
    add_action( 'woocommerce_account_uzleteim_endpoint', 'add_uzleteim_content' );
    
    /**
     * Add content to the new tab.
     *
     * @return  string.
     */
    function add_uzleteim_content() {
    	
    }
    	
    

    I would like to show here at

    function add_uzleteim_content() {
    	
    }

    some information from user profile. I already added to user profile the information fields.
    But I can not display the data on frontend.

    The “Kapcsolattartó neve” is “kapcsolattarto_neve”. I tried shortcodes but did not work, and edit in CodeSnippet but there were some error always.

    Thank you,
    R

  • Solving

    ACF and Woocommerce conflict with billing details country picker

    Hello ACF,

    I have used ACF to built several websites, and i absolutely love working with it.
    Now I have built this woocommerce webshop, with lots ACF supporting it. But I am stumbling upon a big problem which I cannot resolve:

    The built-in Woocommerce country picker for the billing and shipping fields on the checkout page, does NOT show a list of countries while having the ACF plugin activated. This field is essential for clients to able to buy anything from the shop. I cannot hide, remove or ‘unrequire’ this field as the checkout will not be completed.

    When I deactivate the ACF plugin (Version 5.12.2)  the country picker DOES show the list of countries, so it has to be a conflict with ACF, woocommerce and my custom made theme.

    Is there anything to be written in de CSS or anything else?
    Help is very much appreciated as I already spent hours trying to resolve this problem.

    The URL of the website is https://www.objectsofobsession.com
    The url of the checkout page is https://www.objectsofobsession.com/afrekenen/

    Thanks a lot!

  • Solving

    PDF File Upload view on Woocommerce Order Page

    I just added custom field to upload PDF and XLS file on new order in woocommerce platform,

    Now I want to show the uploaded PDF file in order page in my account tab and share the same file as an attachment in e-mail when new order created.

    Please help me resolve the issue.

    Regards

    Vikas Mishra
    Vivid Development Services Pvt Ltd
    9811442146

  • Solved

    Show the ACF field in WooCommerce Category inside the Shop page

    I’ve been cracking my brain over this being a non-programmer. And have gotten so far as to retrieving either the product ID or category ID for each product in the Shop page.

    But I’m stumped on how to combine them to get my ACf field to show.

    Here’s what I got so far..

    function show_shop_suffix() {
    	
    	// If shop page 
    	if ( is_shop() ) {
    		
    		global $product;
    		// to get product ids
    		//$product_id = $product -> get_id();
    		
    		// to show product arrays
    		//$terms = get_the_terms( $product_id, 'product_cat' );
    		
    		// get the product category ids
    		$product_cat_id = wc_get_product_term_ids( $product -> get_id(), 'product_cat' );
    		
    		// vars to get the ACF field and product ID
    		$sugo_loop_item_suffix = get_field( 'product_archive_suffix', 'product_cat' . '_' . $product_cat_id );
    	}
    	
    	echo ($sugo_loop_item_suffix);
    	
    	var_dump ($product_cat_id);
    }
    add_action( 'woocommerce_after_shop_loop_item', 'show_shop_suffix', 5 );

    Entering this code via Code Snippets, instead of a child theme and modifying the WooCommerce template.

  • Solving

    Custom related products on shop page

    I have a WooCommerce shop and want to be able to display custom related products, for each product, on the shop/catalog page.

    My setup
    I have created a field group with a RELATION field called: product_relations

    For each product I have selected several ‘custom related products’ via the product_relations field option on the product page in the backend.

    I then created a shortcode to be visible on the shop/catalog page.

    I do see output only not the output I would like.

    The current output
    I only see the LATEST PRODUCT ITSELF instead of its relations (times the number of custom related products I have selected) >> See screenshot

    Current output

    Here’s my code I have so far:

    
    function yl_product_relations_shortcode() {
        global $product;
    
    	$product_relations = get_field('product_relations');
    
    	if ($product_relations) {
    
    		$output .= '<ul class="uk-thumbnav uk-margin-bottom">';
    
    		foreach ($product_relations as $product_relation) {
    			$title	= get_the_title($product_relation->ID);
    			$image	= get_the_post_thumbnail_url($product_relation->ID);
    			$url	= get_the_permalink($product_relation->ID);
    
    			$output .= '<li><a href="' . $url . '" uk-tooltip="' . $title . '"><img src="' . $image . '" class="uk-border-rounded" width="40"></a></li>';
    		}
    
    		$output .= '</ul>';
    
    	}
    
    	return $output;
    
    }
    
    add_shortcode('yl_product_relations','yl_product_relations_shortcode');
    
  • Unread

    WooCommerce Variation Gallery Deletes Other Field

    Hi All,

    Really hoping someone can help. I’ve got the following code:

    <?php
    ###
    # Add "Product Variation" location rule values
    ###
    function wp_acf_location_rule_values_post_type($choices){
    
    	$keys = array_keys($choices);
    	$index = array_search('product', $keys);
    
    	$position = $index === false ? count($choices) : $index + 1;
    
    	$choices = array_merge(
    		array_slice($choices, 0, $position),
    		array('product_variation' => __('Product Variation', 'auf')),
    		array_slice($choices, $position)
    	);
    
    	return $choices;
    }
    
    add_filter('acf/location/rule_values/post_type', 'wp_acf_location_rule_values_post_type');
    
    ###
    # Add "Product Variation" location rule match
    ###
    function wp__acf_location_rule_match_post_type($match, $rule, $options, $field_group){
    
    	if ($rule['value'] == 'product_variation') {
    
    		$post_type = $options['post_type'];
    
    		if ($rule['operator'] == "==")
    			$match = $post_type == $rule['value'];
    
    		elseif ($rule['operator'] == "!=")
    			$match = $post_type != $rule['value'];
    	}
    
    	return $match;
    }
    
    add_filter('acf/location/rule_match/post_type', 'wp__acf_location_rule_match_post_type', 10, 4);
    
    ###
    # Render fields at the bottom of variations - does not account for field group order or placement.
    ###
    add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) {
        global $wp_i; // Custom global variable to monitor index
        $wp_i = $loop;
        // Add filter to update field name
        add_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
        
        // Loop through all field groups
        $acf_field_groups = acf_get_field_groups();
        foreach( $acf_field_groups as $acf_field_group ) {
            foreach( $acf_field_group['location'] as $group_locations ) {
                foreach( $group_locations as $rule ) {
                    // See if field Group has at least one post_type = Variations rule - does not validate other rules
                    if( $rule['param'] == 'post_type' && $rule['operator'] == '==' && $rule['value'] == 'product_variation' ) {
                        // Render field Group
                        acf_render_fields( $variation->ID, acf_get_fields( $acf_field_group ) );
                        break 2;
                    }
                }
            }
        }
        
        // Remove filter
        remove_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
    }, 10, 3 );
    
    // Filter function to update field names
    function  acf_prepare_field_update_field_name( $field ) {
        global $wp_i;
        $field['name'] = preg_replace( '/^acf\[/', "acf[$wp_i][", $field['name'] );
        return $field;
    }
    
    ###
    # Save variation data
    ###
    add_action( 'woocommerce_save_product_variation', function( $variation_id, $i = -1 ) {
        // Update all fields for the current variation
        if ( ! empty( $_POST['acf'] ) && is_array( $_POST['acf'] ) && array_key_exists( $i, $_POST['acf'] ) && is_array( ( $fields = $_POST['acf'][ $i ] ) ) ) {
            foreach ( $fields as $key => $val ) {
                update_field( $key, $val, $variation_id );
            }
        }
    }, 10, 2 );
    
    ###
    # Rebind the ACF events after the variations are loaded
    ###
    add_action('acf/input/admin_footer', 'wp__acf_input_admin_footer');
    function wp__acf_input_admin_footer() {
    ?>
        <script type="text/javascript">
          (function($) {
            $(document).on('woocommerce_variations_loaded', function () {
              acf.do_action('append', $('#post'));
            })
          })(jQuery);	
        </script>
    <?php      
      }
    

    This creates an option when setting up an ACF group, whereby you can then select the WooCommerce Variable product.
    In my case, I’m then adding a gallery

    Editing a product, if I expand the variable products, I can add/edit/save the images – no problems at all.

    I then needed another ACF field for downloads. This is a file field linked to the post type Product (not variable!).

    If I edit my product, add my download and save – all good!

    If I edit my product in any way, then once I click save, the download file removes the attachment.

    Am totally stumped!

    Any help would be very much appreciated.
    Thanks

  • Unread

    Rule groups not being followed in Dokan product upload for acf

    Hi there,

    I’ve created a rule group for a custom field to appear only when the post is equal to product AND when the post taxonomy is equal to a product category.

    I’ve got vendor allowed edits set to true.

    It’s functioning as I would expect when I try to create a product in admin with woocommerce but not for the sellers in dokan product upload. The custom field is appearing for all products when I only want it to appear when the seller has selected a specific category.

    I’m not sure what i’m doing wrong?

    ps i’ve read other people having the same issues and I understand I need to add some javascript somewhere but i’m new to all this so if it could be explained what i do with this js and where to put it to get around this problem I would be very grateful.

    Many thanks

  • Unread

    Query relationship field, check post status

    Hi, I have the following code to get a woocommerce product, which is connected with a relationship field. How would I check the post status to show only published Products?

    
    <?php
    $related_products = get_field('event_woocommerce_product');
    
    if( $related_products ): ?>
    
    <div class="loop">
    	<?php foreach( $related_products as $post ): 
    		
    // Setup this post for WP functions (variable must be named $post).
    setup_postdata($post); 
    ?>
    
    	<div class="loop-item margin-bottom--m border-bottom--shade-ultra-light margin-bottom--l">
    
    	<?php
    	global $product;
    	$event_tijd = get_post_meta( $product->get_id(), 'event_tijd', true );
    	$event_datum = get_post_meta( $product->get_id(), 'event_datum', true );
    	$date_now = date('Ymd'); // this format is string comparable
    	?>
    
    	<?php if(strtotime($event_datum) >= strtotime($date_now))
    	{
     	?>
    
    		<h4 class="margin-bottom--xs"> <?php echo $product->get_title(); ?> </h4>
    		<div class="text--s margin-bottom--xs"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 20 20">
    				<path id="Path_391" data-name="Path 391" d="M9.063,4.688a.938.938,0,0,1,1.875,0V9.5l3.332,2.219a.9.9,0,0,1,.227,1.3.86.86,0,0,1-1.266.227l-3.75-2.5a.857.857,0,0,1-.418-.781ZM10,0A10,10,0,1,1,0,10,10,10,0,0,1,10,0ZM1.875,10A8.125,8.125,0,1,0,10,1.875,8.124,8.124,0,0,0,1.875,10Z" />
    			</svg>
    			<?php echo $event_tijd;?> </div>
    		<!-- Prijs en button -->
    		<?php
    			echo '<div class="margin-bottom--xs">' . $product->get_price_html() . '</div>';
    		?>
    		<?php
    			echo '<div class="btn--secondary justify-content--center inline-block margin-bottom--xs">';
    		
    				echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    					sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',
    					esc_url( $product->add_to_cart_url() ),
    					esc_attr( $product->get_id() ),
    					esc_attr( $product->get_sku() ),
    					$product->is_purchasable() ? 'add_to_cart_button' : '',
    					esc_attr( $product->get_type() ),
    					esc_html( $product->add_to_cart_text() )
    					),
    				$product );
    			echo '</div>';	
    		?>
    		<!-- /Prijs en button -->
    
    	</div><!-- .loop-item -->
    <?php }
    	else {
        	echo "";
    		}?>
    	<?php endforeach; ?>
    </div> <!-- .loop -->
    
    <?php else: 
    echo 'Nog geen events gepland. Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe events!';
    ?>
    
    <?php 
    // Reset the global post object so that the rest of the page works correctly.
    wp_reset_postdata(); ?>
    <?php endif; ?>
    
  • Solving

    Add from to edit account page two submit buttons

    Hello, I added a from in the frontend edit-account page. There are two submit buttons and the original button is not working. I would be very please if anyone can help.

    function action_woocommerce_edit_account_form(  ) { 
    acf_form_head();
    
        $current_user = wp_get_current_user();
    	$options = array(
    		    'post_id' => 'user_'.$current_user->ID,
    		    'field_groups' => array(84),
    		    'form' => true, 
    		    'return' => add_query_arg( 'updated', 'true', get_permalink() ), 
    		    'html_before_fields' => 'Hello',
    		    'html_after_fields' => 'Yes',
    		    'submit_value' => 'Update' 
    		);
    		acf_form( $options );
    }
    
    add_action( 'woocommerce_edit_account_form', 'action_woocommerce_edit_account_form', 10, 0 );
  • Unread

    Add Google map to billing address and display value in admin order

    Hello,

    I’m new to ACF. I add this code below to this template form-edit-address.php inside <form method="post"></div>

    `<?php
    acf_form_head();
    $current_user = wp_get_current_user();
    $options = array(
    ‘post_id’ => ‘user_’.$current_user->ID,
    ‘field_groups’ => array(27836),
    ‘form’ => false,
    );
    acf_form( $options );
    ?>`

    and I save Google map data with the code below

    function action_woocommerce_customer_save_address( $user_id, $load_address ) { 
        acf_form_head();
    
        $current_user = wp_get_current_user();
    	$options = array(
    		    'post_id' => 'user_'.$current_user->ID,
    		    'field_groups' => array(27836),
    		    'form' => false, 
    		);
    	acf_form( $options );
    }; 
    add_action( 'woocommerce_customer_save_address', 'action_woocommerce_customer_save_address', 10, 2 );

    The Google map get saved after hitting Woocommerce save button. The question is how can I display Google map value in the Admin order edit page using this hook woocommerce_ajax_get_customer_details? I’d like to display the Google map value there.

  • Helping

    Map ACF field with category woocommerce

    Hello,
    I am desperately looking for a solution to my problem.
    I have an online store that enters hundreds of products every day. I’m using advanced fields with ACF with conditional logic.

    I would like the category of woocommerce products to be added automatically when an ACF field is filled.

    can you help me please ?
    Thank you !

  • Solved

    Make custom column sortable by order of custom field value

    In my ACF field group, which is set up for Post Type -> Product. I have added a new field property_reference (Type = Text) to hold an individual reference number. I wanted to display this value in the Products table view for WooCommerce in my Admin WP Dashboard. So I have now created a custom column which outputs this value.

    At the moment I only have three entries, these are BA001, BA002, BA003. However, before things get wild, I would like to be able to sort this custom column in order.

    I have added some code shown below. This makes the Reference ID Column clickable, but provides ‘No products found’ line on the table.

    So in order to make this sortable, to list in the order of the custom field property_reference from highest to lowest. How do I set up the custom field and make use of the meta query?

    I should note I’m a little new to this and still trying to get my head around it 🙂

    Any help or advice would be much appreciated. Thanks

    add_filter( 'manage_edit-product_sortable_columns', 'my_sortable_reference_column' );
    function my_sortable_reference_column( $columns ) {
        $columns['rm_reference'] = 'reference_id';
        return $columns;
    }
    
    function product_rmreference_column_width_query( $query ) {
        if ( is_admin() ) {
            $orderby = $query->get( 'orderby' );
            if ( 'reference_id' == $orderby ) {
                $meta_query = array(
                    'relation' => 'OR',
                    array(
                        'key'     => '_ref',
                        'compare' => '>',
                        'type' => 'NUMERIC'
                    ),
                    array(
                        'key' => '_ref',
                    ),
                );
                
                $query->set( 'meta_query', $meta_query );
                $query->set( 'orderby', 'meta_value' );
            }
        }
    }
    
    add_action( 'pre_get_posts', 'product_rmreference_column_width_query' );
    
    
  • Solved

    Using Shortcode in WP Editor for Woo Product

    Hi, I’m not sure whether this is possible and if not please tell otherwise.

    I’ve set up a Link type field in my group for post type. I’m trying to display this link in a HTML href attribute inside the wysiwyg editor when editing Woocommerce Products.

    For example, the link is to view the product on another website. So in the field when editing the product I’ve inserted the full URL. In the editor, I’ve tried to insert ACF Shortcode.

    <p><a target="_blank" rel="nofollow noopener" title="View Products Details on XYZ">Click Here</a></p> to alternatively view this product Somewhere Else.</p>

    This is an example. I want to display the ‘Click Here’ link in various parts of the editor, so it makes to use a custom field.

    Considering there is no output, I presume I’m doing it wrong?

    Any feedback would be great.

    Thanks,

  • Unread

    interference preview size gallery with woocommerce

    hello

    i created a gallery field in acf and set its preview size to 150×150

    i used the elementor gallery widget to display the gallery field

    if woocommerce plugin is installed, displays full size instead of 150×150 and ignores preview size 150×150

    there are 150×150 images size

  • Helping

    My extra field description on product category page doesn't update when changing

    Hey,
    My extra field description on product category page doesn’t update when changing product category filters. Filters are set to singular use. The default category description changes correctly.

    This is the function I used works fine exept when changing category from the filter:

    add_action( ‘woocommerce_after_main_content’, ‘my_extra_description’ );
    function my_extra_description() {

    global $wp_query;
    apply_filters( ‘acf/update_value’, $value, $post_id, $field, $original );
    # get the query object
    $category = $wp_query->get_queried_object();
    #get the cat ID
    $category_ID = $category->term_id;

    #get the field
    $contenu_categorie = get_field( ‘contenu_categorie’, ‘category_’.$category_ID );
    #if we have data, show it
    if( $contenu_categorie ){
    echo $contenu_categorie;
    }

    }

  • Unread

    Have a CPT checkbox field value specific for each user

    Hello everyone !

    I’m building an online course system using ACF and I want to create a “to do checklist” functionality to every lesson.

    Context :
    Every lesson is a CPT named “lesson”.

    I’m having a repeater field assigned on every lesson CPT allowing the admin to add steps that the user have to follow.

    I’m able to display every row of the repeater dynamically on the front-end with Divi and Divi Engine plugins.

    My need :

    I want to add the ability for the user to check the steps when they are done. So I want to have a checkbox that the user car check or uncheck on the frontend.

    But the problem is that the saved checkbox value need to be specific to 3 levels of information simultaneously : the lesson, the step (repeater row) and the user.

    So in the DB I need to have a table that store for every user the checkbox value for every step defined in each lesson CPT.

    When I add a new lesson with specific steps (repeater rows) I need to be able to edit the value of the checkbox for every users.

    Then I also need to make that work fast (maybe with JSON) because I don’t want to lookup in a huge user list for every single step value. Need to structure data efficiently.

    Some of the methods I’ve tried that didn’t worked :
    I tried to build a system to mirror the fields AND VALUES created in the lessons and make them appear on the user fields and make the checkbox only available on the user side. I tried to use “clone” fields, templates, relational fields, nested repeaters with relational fields, bidirectional relational fields but nothing worked and that created a big mess that I’ve cleaned up.

    Maybe there is a way to have only a specific field on a group assigned to a post type to have a unique value for each user ? I’m lost lol

    PS : I only have very very basic PHP skills, I can understand basic existing codes on a wordpress architecture and bring it little modification but I’m not able to code a plugin from scratch 🙂

    Futures enhancements if the first part is working :
    – Add more type of steps like one asking the user to submit a text allowing the teacher to ask question to check if the lesson is well learned or a more complicated quizz system with a score calculation
    – Filter the data as the courses programs will be structured like this : Program > Module > Lesson and i’m using woocommerce membership to restrict the content
    – By default the data of the steps is displayed on each course lessons but it would be interesting to build a synthesis of the user avancement on a specific page so I would need to be able to print the data based on the user for this page, instead of the lesson.

    Thanks in advance, guys !

  • Unread

    Calculate custom fields and WooCommerce Advanced Bulk Edit

    Hello,

    To calculate some custom fields of our products we use the code described on this topic https://support.advancedcustomfields.com/forums/topic/how-to-create-a-calculated-acf-field-saved-in-the-db/ . This works fine when single editing the products.

    We also use WooCommerce Advanced Bulk Edit to bulk edit our products. Our products consist of many custom fields, so bulk editing them is quicker. Unfortunately the function to calculate the custom fields does’nt work when bulk editing the products.

    I know this is a long shot but does anyone has experience with this or knows a solution to this?

    Kind regards,
    BytEffekt

  • Helping

    ACF and Woocomerce Surcharge

    hi there

    i’m trying to implement a surcharge feature that goes into the woocommerce cart. the code is below, but it doesn’t seem to pickup the custom field, which is ‘surcharge’

    // Packing fee
    add_action( ‘woocommerce_cart_calculate_fees’,’wc_add_surcharge’ );
    function wc_add_surcharge( $cart ) { ?>

    <?php if(get_field(‘surcharge’) != 8) {
    $fee = 4;
    } else { $fee = 8;}

    /** Assign surcharge_fee to fee **/
    $cart->add_fee( ‘Surcharge’, $fee );
    }
    ?>

    any idea why it’s not picking up the value in ‘surcharge’?

  • Solving

    WooCommerce users registration

    I’m trying to build a groups website, based on WooComerece. The website admin approves the submitted group registration form, created and submitted by the group manager. The community manager has a billing and shipping addresses and payments method. Every new user/customer registration form includes a mandatory “Group” field to choose the group from a dropdown single choice list with values of all approved groups ID. The user/customer registration is subject to the group manager, and the new user/customer profile inherits automatically the group manager billing and shipping addresses and payments method. Can your plugin help me achieve these goals by adding custom fields to the user’s database?
    Thank you very much.

Viewing 25 results - 126 through 150 (of 889 total)