I am trying to get a custom attribute of a product 'advance-payment' and 'post_title'
to another page using session. post_title
gets passed but the custom attribute advance-payment
does not. advance-payment
is printed on simple.php but not on 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'];
You can add custom detail to woo commerce session by below hook:
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;
}
by below code you can get cart item from cart session on your 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'];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.