Support

Account

Forum Replies Created

  • Great, thank you John. It did solved the issue.

  • @hube2 @jarvis Forget about my last message. I was able to solve my issue without using ajax.

    Since I have around 1200 products on my site, I just added ‘meta_key’ => ‘pdf_upload’, in the array to filter. It reduced the loading time, now the page load fast!

    Thanks for your help

    Revised code:

    
    <section class="post-content">
                    <ul>
    
                    <?php
                    $args = array(
                      'posts_per_page' => -1,
                      'post_type' => 'product',
                      'orderby' => 'date',
                      'order' => 'DESC',
                      'paged' => $paged,
                      
                      'meta_key'    => 'pdf_upload',  
                    );
                    $wp_query = new WP_Query($args);
                    if ($wp_query->have_posts()) :
                      while ($wp_query->have_posts()) : $wp_query->the_post();
    
                        $pdf_upload = get_field('pdf_upload');
                        if( $pdf_upload ): ?>
                          <li><a href="<?php echo $pdf_upload['url']; ?>"><?php echo $product->post->post_title; ?> </a></li>
                          <?php echo '<span class="date_published">Published on: ' .get_the_date('Y', $product->get_id()) . '</span>'; ?>
    
                        <?php endif;
    
                      endwhile;
                    endif;
                    ?>
    
                    </ul>
                  </section>
  • It dosen’t seems to be working. It now show 3 links in <li>

    There is also a list of products name listed at the bottom of the page

    Just to let you know I did match the value in settings – reading- blog which is 12 for me πŸ™‚

  • @jarvis I had to replace $ with jQuery, to solve this error: ‘Uncaught TypeError: $ is not a function ‘

    Now, I am getting this error: Uncaught ReferenceError: ajax_posts is not defined

    It makes me think that I haven’t proprely enqued the script maybe?

    Also do I need to keep the theme twentytwentyone installed ?

  • @jarvis It work well, here is the modified code below…

    <?php
    $args = array(
      'posts_per_page'  => -1,
      'post_type'     => 'product',
      'orderby'       => 'date',
      'order'         => 'DESC',  
      'paged'       => $paged,
      'fields'      => 'ids'      
    );
    $wp_query = new WP_Query($args);
    if ($wp_query->have_posts()) :
      while ($wp_query->have_posts()) : $wp_query->the_post();
    
      $pdf_upload = get_field('pdf_upload');
      if( $pdf_upload ): ?>
           <li> <a href="<?php echo $pdf_upload['url']; ?>"><? echo $product->post->post_title; ?></a></li>
           <?php echo '<span class="date_published">Published on: ' . get_the_date('Y', $product->get_id()) . '</span>'; ?>
    
        <?php endif; 
    
      endwhile;
    endif;
    
    ?>

    @hube2 The page is indeed pretty slow, I will work on the Ajax now, I will keep this thread updated with the code.

    Thanks

  • Hi,

    I am trying to update a custom field ( in the woocommerce order page). Once the field is saved, I then change the status email to complete and send the number into the order completion email. using this code:

    // define the woocommerce_email_before_order_table callback 
    function action_woocommerce_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) { 
        
        
        if (get_field('ACFFIELDNAME', $order->get_id())) { // Only show if field is filled
     
    ?>
            <h3>Your number: <?php the_field('ACFFIELDNAME', $order->get_id()); ?></h3>
                  
            <?php 
            
        }
    
    }; 
             
    
    // add the action 
    add_action('woocommerce_email_before_order_table', 'action_woocommerce_email_before_order_table', 10, 4 );
    
    
  • Hi,

    I created a custom field to add manually the tracking number in the woocommerce order page.

    The problem is that in order to work, I have to fill in the field, save the page, then I have to change the order to complete and resave the page.

    It’s like if the information entered in the field was not saved. Is there a way I can add a save button under my custom field? This could fix the issue.

    The information entered would be registered in the wordpress DB and then I could only switch the order status to complete, in order to send the tracking number to the client.

    Here is my code

    // define the woocommerce_email_before_order_table callback 
    function action_woocommerce_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) { 
        
        
        if (get_field('trackingnumberups', $order->get_id())) { // Only show if field is filled
     
    ?>
            <h3>Your tracking number: <?php the_field('trackingnumberups', $order->get_id()); ?></h3>
            You may track your order with the number above, here: <a style="color: #0073aa;" href="https://www.ups.com/tracking/tracking.html">UPS Tracking</a> 
             
            <?php 
            
        }
    
    }; 
             
    // add the action 
    add_action('woocommerce_email_before_order_table', 'action_woocommerce_email_before_order_table', 10, 4 ); 
  • Hi zaehlpixel,

    I use the same code than you for my woocommerce store.

    The problem is that I have to add the DHL tracking code, hit save, then mark the order as complete and save again.

    If I just change the status to order complete, add the tracking number, hit save, it won’t include the tracking number in the order completion email.

    Have you experienced the same issue?

Viewing 8 posts - 1 through 8 (of 8 total)