我正在使用woo Commerce中的购物车挂钩。 我想知道是否可以将图像作为自定义属性添加到购物车。
例如,我包括了这样的自定义属性:
// Store the custom data to cart object
add_filter( 'woocommerce_add_cart_item_data', 'save_custom_product_data', 10, 2 );
function save_custom_product_data( $cart_item_data, $product_id ) {
$bool = false;
$data = array();
if( isset( $_REQUEST['pa_engraving'] ) ) {
$cart_item_data['custom_data']['pa_engraving'] = $_REQUEST['pa_engraving'];
$data['pa_engraving'] = $_REQUEST['pa_engraving'];
$bool = true;
}
if( $bool ) {
// below statement make sure every add to cart action as unique line item
$cart_item_data['custom_data']['unique_key'] = md5( microtime().rand() );
WC()->session->set( 'custom_variations', $data );
}
return $cart_item_data;
}
// Displaying the custom attributes in cart and checkout items
add_filter( 'woocommerce_get_item_data', 'customizing_cart_item_data', 10, 2 );
function customizing_cart_item_data( $cart_data, $cart_item ) {
$custom_items = array();
if( ! empty( $cart_data ) ) $custom_items = $cart_data;
// Get the data (custom attributes) and set them
if( ! empty( $cart_item['custom_data']['pa_engraving'] ) )
$custom_items[] = array(
'name' => 'pa_engraving',
'value' => $cart_item['custom_data']['pa_engraving'],
);
return $custom_items;
}
现在我可以将我的图像用作Base64
图像,并且想知道是否可以像这样轻松地将其作为自定义属性进行传输:
https://myexampleshop.com/?add-to-cart=76981&quantity=1&image=data:image/png;base64,iVBORw0KGgoAAAANSUhEUg......
这是要走的路,还是有其他任何技术可以使用购物车钩子将图像添加为自定义属性。