跳到内容 跳到侧边栏
Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 12:00 7:00 – 12:00 7:00 – 12:00 7:00 – 12:00 7:00 – 12:00 -
- 13:00 – 16:00 13:00 – 16:00 13:00 – 16:00 13:00 – 16:00 13:00 – 16:00 -

支持人员时区: America/Lima (GMT-05:00)

本主题包含 0 則回覆 ,有 1 声音 。

最后由 Eslam Badr 1 year, 5 months前 更新。

协助者:: Nicolas V..

作者 帖子
28 6 月, 2024 于 5:22 下午 #15853552

Eslam Badr

Background of the issue:
I am currently using the Product Feed Pro plugin along with WooCommerce and WooCommerce Multilingual & Multicurrency. I have added a custom field to my products to store a converted price in USD. The custom field "_converted_price" is visible and functioning correctly within the WooCommerce product edit screen. I added the following code to my theme's functions.php to create and save the custom field "_converted_price":

add_action('woocommerce_product_options_general_product_data', 'add_converted_price_custom_field');
add_action('woocommerce_process_product_meta', 'save_converted_price_custom_field');

function add_converted_price_custom_field() {
woocommerce_wp_text_input(
array(
'id' => '_converted_price',
'label' => __('Converted Price (USD)', 'woocommerce'),
'desc_tip' => 'true',
'description' => __('Enter the converted price in USD.', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
}

function save_converted_price_custom_field($post_id) {
$converted_price = isset($_POST['_converted_price']) ? sanitize_text_field($_POST['_converted_price']) : '';
update_post_meta($post_id, '_converted_price', $converted_price);
error_log("Saved converted price: $converted_price for product ID: $post_id");
}

add_filter('wcml_get_currency_converted_price', 'my_convert_price_to_USD', 10, 3);

function my_convert_price_to_USD($converted_price, $price, $target_currency) {
if ($target_currency === 'USD') {
return $converted_price;
} else {
$exchange_rates = get_option('wcml_exchange_rates');
$qatar_riyal_exchange_rate = isset($exchange_rates['QAR']['rate']) ? $exchange_rates['QAR']['rate'] : 1;
$converted_price_to_usd = $price / $qatar_riyal_exchange_rate;

global $post;
if (is_object($post)) {
update_post_meta($post->ID, '_converted_price', $converted_price_to_usd);
error_log("Converted price to USD: $converted_price_to_usd for product ID: {$post->ID}");
} elseif (is_object($product)) {
update_post_meta($product->get_id(), '_converted_price', $converted_price_to_usd);
error_log("Converted price to USD: $converted_price_to_usd for product ID: {$product->get_id()}");
}

return $converted_price_to_usd;
}
}

The custom field "_converted_price" appears correctly on the WooCommerce product edit screen, and its values are saved without issues.

my web is : 隐藏链接

Symptoms:
I am unable to select or map the custom field "_converted_price" within the Product Feed Pro plugin to include it in my Google Merchant Center feed.

Questions:
How can I ensure that the custom field "_converted_price" is recognized and available for selection in the Product Feed Pro plugin?
Are there any additional steps or configurations required to include this custom field in my product feed for Google Merchant Center?

主题'[關閉] Custom Field'已关闭,不接受新回复。