Join our new community forum for support & discussion
Join NowHome › Support › Extensions › Paid Listings › Checkout doesn’t show what listing is being paid to be featured
Checkout doesn’t show what listing is being paid to be featured
-
AuthorPosts
-
joseantonio 2 years, 8 months ago
Hello. I am very happy all these solutions from this plugin.
I have this question: after user click on Feature button, checkout page loads, shows up the product name. But it doesn’t show what listing is being paid to be featured.Tried to search over documentation where the code goes found this:
// Add product to cart.
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id, 1, 0, [], [ ‘hp_listing’ => $listing->get_id() ] );return wc_get_page_permalink( ‘checkout’ );
But as I am a newbie, didn’t know what to do for getting the info on the checkout.
Searching on the web, got this code:add_filter( ‘woocommerce_add_cart_item_data’, function ( $cartItemData, $productId, $variationId ) {
$cartItemData[‘myCustomData’] = ‘someCustomValue’;return $cartItemData;
}, 10, 3 );add_filter( ‘woocommerce_get_cart_item_from_session’, function ( $cartItemData, $cartItemSessionData, $cartItemKey ) {
if ( isset( $cartItemSessionData[‘myCustomData’] ) ) {
$cartItemData[‘myCustomData’] = $cartItemSessionData[‘myCustomData’];
}return $cartItemData;
}, 10, 3 );
add_filter( ‘woocommerce_get_item_data’, function ( $data, $cartItem ) {
if ( isset( $cartItem[‘myCustomData’] ) ) {
$data[] = array(
‘name’ => ‘My custom data’,
‘value’ => $cartItem[‘myCustomData’]
);
}return $data;
}, 10, 2 );
add_action( ‘woocommerce_add_order_item_meta’, function ( $itemId, $values, $key ) {
if ( isset( $values[‘myCustomData’] ) ) {
wc_add_order_item_meta( $itemId, ‘myCustomData’, $values[‘myCustomData’] );
}
}, 10, 3 );Tried to put [ ‘hp_listing’ => $listing->get_id() ] inside this functions but couldn’t make it work…
Any ideas of how an I get this?joseantonio 2 years, 8 months agoHere is the image of how the functions behave.
joseantonio 2 years, 7 months agoHey forget all I said above.
I figured it out how to get the id number of the listing on the checkout page.
I added $cart_item[‘hp_listing’ ] in /wp-content/plugins/woocommerce/templates/checkout/review-order.php
Now my question is another one…
I have a listing ID (example:43). How can I get the name of the listing? Regarding that the code goes on the file mentioned above, ou of hivepress filetree.Listing is just a custom post type so you can get it with this function https://developer.wordpress.org/reference/functions/get_the_title/
Please don’t edit the plugin or theme files directly because any changes may be erased on update, you can use a child theme or HivePress/WooCommerce API actions and filters.
-
AuthorPosts
New Reply
This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.