最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Place product field value as variable in php

programmeradmin2浏览0评论

I have created a new field using ACF for woocommerce. The field is called "position" and has default value 52.

Now I want this value as a php variable in a image generation script.

Inside one function I have:

$position = get_field('position');

and

echo '<input type="hidden" name="position2" value="'.$position.'" id="position2" >';

At frontend I see that field "position2" is filled with the product field value 52. So that works!

In a different function in the same php file, I am trying to reuse this variable, and I can't get it to work. I need $position to represent '52' in below code.

function _create_image( $ax1, $ax2, $ax3 ) {
...
imagecopy($template, $sky, 148, $position, 0, 0, 660, 660);
...
}

If I do this, $position is an empty value in this function. I have tried global, and 'use $position', but I can't seem to get it working.

发布评论

评论列表(0)

  1. 暂无评论