Support

Account

Home Forums Search Search Results for 'woocommerce'

Search Results for 'woocommerce'

reply

  • To add to this, are you using WooCommerce for products and orders?

    If so, a pseudo answer would be something like:

    Look at transition_post_status
    When the post is updated, you need to get the post ID

    You then need to Get List of WooCommerce Customer Emails Who Purchased a Specific Product

    Now you have the customer email, you can use wp_mail()

    Hope that helps!

  • I found the hook. This worked for me, if anyone is also having issues with links or gutenberg blocks in the WooCommerce checkout terms and conditions checkbox field:

    /**
     * Replace wc_terms_and_conditions_page_content to apply the_content filter to markup
     */
    function my_wc_terms_and_conditions_page_content() {
    	$terms_page_id = wc_terms_and_conditions_page_id();
    
    	if ( ! $terms_page_id ) {
    		return;
    	}
    
    	$page = get_post( $terms_page_id );
    
    	if ( $page && 'publish' === $page->post_status && $page->post_content && ! has_shortcode( $page->post_content, 'woocommerce_checkout' ) ) {
    		//echo '<div class="woocommerce-terms-and-conditions" style="display: none; max-height: 200px; overflow: auto;">' . wc_format_content( wp_kses_post( $page->post_content ) ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    		echo '<div class="woocommerce-terms-and-conditions" style="display: none; max-height: 200px; overflow: auto;">' . apply_filters( 'the_content', $page->post_content ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    	}
    }
    remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
    add_action( 'woocommerce_checkout_terms_and_conditions', 'my_wc_terms_and_conditions_page_content', 30 );
  • I suspect you are using a third party addon called “Justified Image Grid”?

    What your current code does is replace the image IDs that woocommerce uses to generate the gallery with IDs provided by an ACF field.

    The “Justified Image Grid” field is a field that outputs different content. Even if you managed to get WooCommerce to use the images selected in that field you wouldn’t get the grid that I assume you’re after.

    What you could try however:

    //Remove the default product gallery entirely
    remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
    
    //Output the justified image grid instead
    add_action( 'woocommerce_before_single_product_summary', 'my_justified_image_grid', 20 );
    function my_justified_image_grid() {
        the_field('proimages');
    }

    I don’t know if this will work out-of-the-box.

  • From a rendering perspective, the field group within Woocommerce looks pretty bad but can probably be fixed up with custom CSS. I’m kind of surprised there isn’t already more support for using both of these 2 pretty popular plugins together.

  • No, both traditional ACF field group and ACF group added into Woocommerce do not contain the same field(s). I’ve found that you need to manually save the ACF fields within woocommerce_process_product_meta. Feels a little dirty, but it works.

        add_action( 'woocommerce_product_options_general_product_data', function() {
            acf_form([
                'post_id' => get_the_ID(),
                'field_groups' => [233],
                'form' => false,
            ]); 
        });
    
        add_action( 'woocommerce_process_product_meta', function($post_id) {
            if (!empty($_POST['acf'])) {
                foreach($_POST['acf'] as $key => $value) {
                    update_field($key, $value, $post_id);
                }
            }
        });
  • Gave it a shot. With the code below custom field data is not saved from the embedded field group. I’m also noticing ACF fields in other groups (added to the post type the normal way) is also not saved. When the Woocommerce code is removed other field group does save.

        add_action( 'woocommerce_product_options_general_product_data', function() {
            echo '<div class="options_group">';        
            acf_form([
                'field_groups' => [233],
                'form' => false,
            ]); 
            echo '</div>';
        });
  • HI @yett

    I think you would need to add the field to the order not the product.

    You then need to add the code to the emails:

    
    /**
     * Add a custom field (in an order) to the emails
     */
    add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
    
    function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
        $fields['Begindatum'] = array(
            'label' => __( 'Begin Datum' ),
            'value' => get_post_meta( $order->id, 'Begindatum', true ),
        );
        return $fields;
    }
    

    If you’re using a plugin for the invoices, you may need to check if they have any hooks

  • I’ll share the solution with you.
    I just understood that in the acf_form () function; you had to pass all the form tags.
    Whose input action
    Here is the script that works to adapt of course to your needs:

    /*====Shortcode contenu News Tab  - ACF  ================= */
    
    add_action( 'admin_post_adaptiveweb_save_profile_form', 'adaptiveweb_save_profile_form' );
    function adaptiveweb_save_profile_form() {
      if(!isset($_REQUEST['user_id'])) return;
    
      do_action('acf/save_post', $_REQUEST['user_id']);
    
      wp_redirect(add_query_arg('updated', 'success', wp_get_referer()));
      exit;
    }
    
    /* Contenu ACF dans Shortcode */
    
    function contenu_shortcode_onglet( $atts ) {
    
    $user_ID = get_current_user_id();
    $user = wp_get_current_user();
    
    $options = array(
        // 'field_groups' => ['group_618a52d0b2b74'],
        
        'fields' => [
            'field_618a52d0b874e',
            'field_618a52d0b878d',
            'field_618a52d0b87ce',
            'field_618a52d0b880f',
            'field_618a52d0b870d',
            'field_618a526a02cd7',
            'field_618a526a02d0f'
    
        ],
    
        'form_attributes' => [
            'method' => 'POST',
            'action' => admin_url("admin-post.php"),
        ],
    
        'html_before_fields' => sprintf(
            '<input type="hidden" name="action" value="adaptiveweb_save_profile_form">
            <input type="hidden" name="user_id" value="user_%s">', $user->ID
        ),
    
        'post_id' => "user_{$user->ID}",
        'form' => true,
        'html_submit_button' => '<button type="submit" class="acf-button button" value="Update Profile">Update Profile</button>',
        'updated_message' => __('<div class="woocommerce-message" role="alert">
            Les détails du compte ont bien été modifiés.</div>', 'acf')
        
    );
    
    acf_form($options);
    
    }
    add_shortcode( 'onglet', 'contenu_shortcode_onglet' );
  • Getting and displaying product variations sounds like a question for WooCommerce.

  • If you name your acf fields the same as the woocommerce ones, it might work.
    It may be worth checking in the database the exact name, as it might be something like _price.

  • Did you manage to do that with Elementor? I am having the same issue. A custom taxonomy’s featured image (under WooCommerce product post type) (field created with ACF) can’t be displayed. Although category’s featured image can be displayed…

  • Hi jarvis,

    thanks a lot for your input! You are right for vanilla Woocommerce Reviews. I tried it myself and it works. The problem is, I am already using a plugin that enhances the Woocommerce Reviews and I try to extend this plugin with those custom fields. The method you explain doesn’t work with this plugin. Only in the backend but not in the frontend form.

    I worked on this issue and managed to get a bit further.
    (with help of this artivle https://medium.com/techcompose/how-to-add-advanced-custom-fields-acf-to-a-frontend-form-2b89c8cfdcee)

    <?php
    $new_post= array(
    ‘post_id’ => ‘new_post’,
    ‘field_groups’ => array(21112),
    ‘post_title’ => false,
    ‘post_content’ => false,
    ‘form’ => false
    );
    acf_form( $new_post);
    ?>

    This way the I do not get an additional submit button and the original submit button still works. I can submit reviews this way. The only problem remaining. Only the original Inputs get saved. The Inputs of the new custom fields do not.

    I assume I am still doing something wrong in the code that goes into functions.php

    add_filter(‘acf/pre_save_post’, ‘save_post_from_frontend’);
    function save_post_from_frontend( $post_id) {

    //Check if user loggin or can publish post
    if( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
    return;
    }

    // check if this is to be a new post
    if( $post_id!= ‘new_post’) {
    return $post_id;
    }

    $post= array(
    ‘post_type’ => ‘w2rr_review’, // Your post type ( post, page, custom post type )
    ‘post_status’ => ‘publish’, // (publish, draft, private, etc.)
    );
    // insert the post
    $post_id= wp_insert_post( $post);
    // Save the fields to the post
    do_action( ‘acf/save_post’, $post_id);
    return $post_id;

    }

  • Thank you Jarvis, already tried it but did not work, seems that “ACF” and “Woocommerce custom tabs” got disconnected at DB level so I’m afraid I will have to manually log in each product wait for the db to sync and save… multiplied 500 times… will take a week.

  • @hube2 Thank you for your answer. I will try to supply with more context.

    The idea is as follows: When a order is completed I use the woocommerce_thankyou action in WooCommerce to create an email as follows:

    add_filter('woocommerce_thankyou', [$this, 'create_email'], 10, 1);

    In my custom fields setup, I’ve created a field group that applies to all products. In the field group I can set a supplier for the product from predefined options in a single select.

    What I want is to access that supplier on a product level in the create_email function that runs after an order is completed. My approach is as follows:

    
    public function create_email($order_id)
        {
            global $product;
    
            $order = wc_get_order($order_id);
            $items = $order->get_items();
    
            $subject = 'NEW ORDER #' . $order->get_order_number();
            $header = 'New order: #' . $order->get_order_number();
    
            foreach ($items as $item_key => $item) {
                $product = $item->get_product();
    
                if (strpos($product->get_slug(), 'vareproeve')) {
                    continue;
                }
    
                $product_id = $item->get_product_id();
    
                 $main .= '<p>ID: ' . $product_id . '</p>';
    
                    if ($supplier = get_field("supplier", $item->get_product_id())) {
                        $main .= '<p><strong>' . __('Supplier: ') . ': </strong>' . $supplier . '</p>';
                    }
    
            }
    
           // Setup rest of email
            if ($main != '') {
                $body = $head . $main . $foot;
    
                $this::send_email($recipient, $subject, $header, $body, $headers, $attachments, $order, $order_id);
                update_post_meta($order_id, '_order_mail_sent', 'yes');
                unset($head);
                unset($main);
                unset($foot);
            }
        }
    
    
  • Hello @infomyweb @joseayram

    You can check this plugin, it will solve your problem.
    https://krazyplugins.com/product/acf-for-woocommerce/

    Thanks

  • Hello @fritserasmus

    To create the custom field for the customer registration form you can assign a role that is equal to the customer from the rules setting. This will not create a custom field in the my-account register form. For this, you will need another plugin as ACF adds that custom field for editing the user page in the backend.

    Here is the addon which can work for you.
    https://krazyplugins.com/product/acf-for-woocommerce/

    Thanks

  • Hello @nugerama

    This solution should work for you:
    https://krazyplugins.com/product/acf-for-woocommerce/

    Thanks

  • Hello @lars555

    This might solve your problem:
    ACF For WooCommerce

    Thanks

  • Can you provide a screenshot? People can be wary of clicking 3rd party links to unknown sites.

    Having not clicked, if the site is WooCommerce(?), you could look to use either a hook or add the relevant template to your theme.

    If its a specific theme, you would need to locate the necessary file and add your code for the custom field (price?) in the relevant place.

  • I suspect you would need to run a CRON daily which would trigger a script/function.

    That script/function can then run the code to update your date.

    Where does $post_id come from? Is it a custom post or a WooCommerce order?

    Is it a published post or in a set status?

    Basically, your script could simply be a WP Query that loops whatever the post type is, it should then update the post meta as you add your code above in the loop

  • Hi @ashisharyal64gmail-com

    I think I had similar but found you can alter the API output. For me, I needed to customise the API response for WooCommerce, here’s the code I used which may help:

    // Custom API Data
    function product_compact_post( $data, $post, $request ) {
    	
    	$categories = get_the_term_list( $data->data['id'], 'product_cat' );	
    	$categories = strip_tags( $categories );	
    
    	$product   = wc_get_product( $data->data['id'] );
    	$image_id  = $product->get_image_id();
    	$image_url = wp_get_attachment_image_url( $image_id, 'full' );		
    
    	$brands = get_the_term_list( $data->data['id'], 'product_brand' );	
    	$brands = strip_tags( $brands );
    	
    	$model = get_field('model', $data->data['id']);
    	
    	$sku = str_replace( array(' ', '&', '/'), array('_', '', ''), $model );		
    	
    	return [
    		'id'		=> $data->data['id'],
    		'sku'		=> $data->sku = $sku,
    		'name'		=> $data->data['title']['rendered'],
    		'link'		=> $data->data['link'],
    		'categories'=> $data->categories = $categories,
    		'image' 	=> $data->image = $image_url,		
    		'manufacturer'	=> $data->manufacturer = $brands,
    		'model'		=> $data->model = $model,
    		'mpn' 		=> $data->mpn = $model,
    		'ean' 		=> $data->ean = get_field('ean', $data->data['id'])		
    	];    
        return $data;
    }
    add_filter( 'rest_prepare_product', 'product_compact_post', 10, 3 );

    You may be able to edit for your needs.

    Hope that helps!

  • Thanks @jarvis for your help.
    I am using Divi theme.
    And yes I am talking about WooCommerce variations for a product.
    But I guest the frontend of teh product page is linked to Woocommerce not Divi ?…

  • Hi @pat0726

    I’m assuming you’re referring to the output of the field on the frontend?

    When you mention variations form, is this WooCommerce or something else?

    From what I can gather, you need to review your template where the code to output the ACF field is being displayed. Then locate the code for the variations form output and move your ACF code below.

    Maybe say which theme you’re using, include screenshots. The more info here, the more people can help.

  • Hi @johndoea

    To show the field, you would need to use something like:

    <?php
    $field_name = get_field('field_name');
    if( $field_name ):
      echo $field_name;
    endif;

    As for the position, you would need to locate the correct template in WooCommerce, usually, you then copy this to your theme and amend it OR use a WooCommerce hook to output the field.
    Given what you’ve said about product tags, you should read this as it may help with where to place the code

  • Hi @brianwaxingmedia-com

    I wonder if you need to use the woo product TAB callback.

    So something like:

    <?php
    ########################
    # Add Custom Product Page TAB
    ########################
    add_filter( 'woocommerce_product_tabs', 'acf_woo_new_product_tab' );
    function acf_woo_new_product_tab( $tabs ) {
    	
    	global $product;
    	$product_id = $product->get_id();	
    	if( have_rows('details_repeater',$product_id ) ):
    		while( have_rows('details_repeater',$product_id ) ) : the_row();
    			if (get_sub_field('title') == 'Characteristics') :
    			// Adds the new tab
    			$tabs['product_details_tab'] = array(
    				'title' 	=> __( 'Characteristics', 'woocommerce' ),
    				'priority' 	=> 10,
    				'callback' 	=> 'acf_product_details_tab_content'
    			);	
    			endif;
    		endwhile;
    	endif;
    	
    	return $tabs;
    
    }
    
    function acf_product_details_tab_content() {
    
    	global $product;
    	$product_id = $product->get_id();
    	
    	// Check rows exists.
    	if( have_rows('details_repeater',$product_id ) ):
    		echo '<h2>Characteristics</h2>';
    		// Loop through rows.
    		while( have_rows('details_repeater',$product_id ) ) : the_row();
    
    			// Load sub field value.
    			$content = get_sub_field('content');
    			echo $content;
    
    		// End loop.
    		endwhile;
    
    	// No value.
    	else :
    		// Do something...
    	endif;	
    	
    }

    Code is untested but hopefully, you can see what’s happening.

Viewing 25 results - 426 through 450 (of 889 total)