Home Forums General Issues How to use this code in acf ?


How to use this code in acf ?

  • <?php
    $slider_off = get_field('slider_off', 'option');
           <?php if ($slider_off) { ?>
                <div class="special-discounts col-xxxl-3 col-xl-4 col-lg-4">
                    <div class="swiper mySwiper">
                        <div class="swiper-wrapper">
                            <?php foreach ($slider_off as $list) {
                                $item = $list['slider_off_product'];
                                $pro_id = $item->ID;
                                $myproduct = new WC_Product($pro_id);
                                $product = wc_get_product($pro_id);
                                $account_game = $product->get_attribute('platform');
                                $product_type = $product->get_type();
                                $stock = $myproduct->get_stock_quantity();
                                $pro_old_price = $myproduct->get_regular_price();
                                $pro_new_price = $myproduct->get_sale_price();
                                $pro_title = $product->get_name();
                                $pro_image = get_the_post_thumbnail($pro_id, array(192, 192));
                                $pro_link = get_permalink($pro_id);
                                $product_logo_pic = get_field('product_logo_pic', $item);
                                $differenceInSeconds = 0;
                                if ($product_type == 'variable') {
                                    $variations = $product->get_available_variations();
                                    $variations_id = wp_list_pluck($variations, 'variation_id');
                                    if (!empty(get_defualt_attr($product))) {
                                if ($product->is_type('variable')) {
                                    // Array row output
                                } else {
                               <!-- code -->
                            <?php } ?>
            <?php } ?>

    HI, I can make the slider_off true or false , but I can’t make a connection between the slider_off_product and the product post in woocommerce ! How should I act to display the product post in this code? In fact, what is the meaning of the $item = $list[‘slider_off_product’]; in the code? And how should it be implemented in acf plugin ?
    sorry for my bad english.

  • Where did you find this code? You have supplied no context

    “slider_off” is a field saved on an ACF options page, not a value saved to a WC product.

    $slider_off = get_field('slider_off', 'option');
  • hi . I am a beginner in coding and this code is a professional template to display special discounts on the home page. I intend to use this code in my theme. I understand that I have to use $slider_off = get_field('slider_off', 'option'); in the template options page and I have already used it and it works fine for enabling/disabling. But I can’t make a connection between this code $item = $list['slider_off_product']; and the WooCommerce post. I don’t understand how it communicates with the product and displays product information. Thank you for your help in this matter.

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

You must be logged in to reply to this topic.