在WooCommerce中,我想添加自定义文本到我的产品显示,这将从产品的编辑页面中的自定义字段抓取。
这就是现在的样子:
我找到了一些自定义php代码来在产品的页面中添加自定义字段,如下所示:
// Display Fields
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
function woocommerce_product_custom_fields()
{
global $woocommerce, $post;
echo '<div class="product_custom_field">';
// Custom Product Text Field
woocommerce_wp_text_input(
array(
'id' => '_custom_product_text_field',
'placeholder' => 'Custom Product Text Field',
'label' => __('Custom Product Text Field', 'woocommerce'),
'desc_tip' => 'true'
)
);
}
function woocommerce_product_custom_fields_save($post_id)
{
// Custom Product Text Field
$woocommerce_custom_product_text_field = $_POST['_custom_product_text_field'];
if (!empty($woocommerce_custom_product_text_field))
update_post_meta($post_id, '_custom_product_text_field', esc_attr($woocommerce_custom_product_text_field));
}
如何显示产品标题下的自定义域
更新:
尝试此自定义挂钩函数,它将在产品标题下面显示自定义域值:
add_action( 'woocommerce_after_shop_loop_item_title', 'custom_field_display_below_title', 2 );
function custom_field_display_below_title(){
global $product;
// Get the custom field value
$custom_field = get_post_meta( $product->get_id(), '_custom_product_text_field', true );
// Display
if( ! empty($custom_field) ){
echo '<p class="my-custom-field">'.$custom_field.'</p>';
}
}
代码放在您的活动子主题(或活动主题)的function.php文件中。
我正在使用名为高级定制字段(ACF)和WooCommerce的插件。我想为WooCommerce产品变体创建一个文本和图像字段。我在ACF中创建了字段,并将它们分配给。 但是在下没有看到这些字段。我搜索了,看起来我必须写一个自定义代码来适应这些字段。我试着搜索这个问题,我创建的大多数建议和教程都是关于通过代码创建自定义字段,而不是使用ACF,这对我没有帮助,因为字段必须使用ACF,这是因为我使用V
在WooCommerce中,我想将自定义文本添加到我的产品显示中,这将从产品编辑页面的自定义字段中抓取。 这就是它现在的样子: 您可以在下面看到标题的产品: 网站链接
null 我用在OceanWP主题上。
我试图在单个产品页面上显示自定义文本“price only visible for logged in users”,但仅当,具有当前中的值时。 当加载单个产品页面时,我找不到实现当前产品post_id的正确SQL查询。 下面是我的代码:
我有一家woocommerce商店,想定制我的产品。用户直接访问类别页面,无店铺存档页面。 你有没有什么好的方法来定制订单?我试着使用插件,并给那些产品一个编号。。。但一切都没有奏效。 问候