我的目标是在购物车项目,我必须显示一个链接与每个产品。
-在购物车页面上结帐-在后端中的订单摘要
当我点击链接时,打开链接目标网站或文件。
现在,我可以在每个购物车项目上保存自定义标题或文本,当我试图传递链接标签时,它只显示没有链接的文本。
我使用这个链接来存档一个目标来显示文本,但是现在我需要链接而不是文本。
发布于 2019-09-24 09:26:12
您可以为您的需求使用下面的代码。它将添加网站/文件网址到购物车页,结帐页和订单摘要在后端。
您需要为产品页面中的网站/文件url创建一个自定义字段。https://prnt.sc/pa7fyg
该网址/链接将显示在:
您可以根据需要更改文本/标签。
/*
# add link filed above add to cart button
*/
function output_web_file_url_field() {
global $product;
$id = $product->get_id();
$web_file_url = get_post_meta($id,"file_website_url",true);
if(!empty($web_file_url)){
?>
Website/file
__( 'Website/file', 'iconic' ),
'value' => sprintf( __( 'Link'), $cart_item['web-file-url']),
'display' => '',
);
return $item_data;
}
add_filter( 'woocommerce_get_item_data', 'display_web_file_url_cart', 10, 2 );
/*
# Add Link to order.
*/
function add_web_file_url_to_order_items( $item, $cart_item_key, $values, $order ) {
if ( empty( $values['web-file-url'] ) ) {
return;
}
$item->add_meta_data( __( 'Website_file_url', 'iconic' ), sprintf( __( 'Link'), $values['web-file-url']) );
}
add_action( 'woocommerce_checkout_create_order_line_item', 'add_web_file_url_to_order_items', 10, 4 );我已经测试过代码,它正在工作。如果这对你有用,请告诉我!
https://wordpress.stackexchange.com/questions/348946
复制相似问题