[英]Passing custom attribute of product using sessions woocommerce
我正在嘗試使用會話將產品'advance-payment' and 'post_title'
的自定義屬性獲取到另一個頁面。 post_title
被傳遞,但是自定義屬性advance-payment
未被傳遞。 advance-payment
打印在simple.php上,而不打印在custom_form.php上。
simple.php
<?php
session_start();
$_SESSION['post_title_form'] = $product->post->post_title;
$ca_advance_value = $product->get_attribute('advance-payment');
$_SESSION['post_advance_form']=$ca_advance_value;
//attribute is echoed here
echo "Test " . $ca_advance_value;
custom_form.php
<?php
session_start();
/* Template Name: CustomFormPage */
//is displayed
echo "TEST 1: " .$_SESSION['post_title_form'];
//not displayed
echo "TEST 2: ".$_SESSION['post_advance_form'];
您可以通過以下鈎子向woo Commerce會話添加自定義詳細信息:
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_custom_data_vase', 10, 2 );
function add_cart_item_custom_data_vase( $cart_item_meta, $product_id ) {
global $woocommerce;
$cart_item_meta['post_title'] = 'post title';
$cart_item_meta['post_advance_form'] = 'Advance Payment';
return $cart_item_meta;
}
通過以下代碼,您可以在custom_form.php上的購物車會話中獲取購物車商品:
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$post_title = $values['post_title'];
$post_advance_form = $values['post_advance_form'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.