MultivendorX Pro
-
AuthorPosts
-
-
May 18, 2023 at 2:00 PM #192242AnonymousInactive
Hi there. We’re trying to display each of the store descriptions for products in the cart at the top of both the Cart & Checkout pages. We have the following code:
/**
* Display MultivendorX store descriptions on top of checkout and cart pages
*/
function display_multivendorx_store_descriptions() {
// Get the current cart
$cart = WC()->cart;// Get all unique vendor IDs from the products in the cart
$vendor_ids = array();
foreach ($cart->get_cart() as $cart_item) {
$product_id = $cart_item[‘product_id’];
$vendor_id = wcmp_get_vendor_id_by_product($product_id);
if ($vendor_id && !in_array($vendor_id, $vendor_ids)) {
$vendor_ids[] = $vendor_id;
}
}// Display MultivendorX store descriptions if available
if (!empty($vendor_ids)) {
echo ‘<div class=”vendor-descriptions”>’;foreach ($vendor_ids as $vendor_id) {
$store_description = get_user_meta($vendor_id, ‘vendor_page_description’, true);if (!empty($store_description)) {
echo ‘<div class=”vendor-description”>’ . wpautop($store_description) . ‘</div>’;
}
}echo ‘</div>’;
}
}
add_action(‘woocommerce_before_checkout_form’, ‘display_multivendorx_store_descriptions’, 5);
add_action(‘woocommerce_before_cart’, ‘display_multivendorx_store_descriptions’, 5);Which causes a fatal error.
It appears that the wcmp_get_vendor_id_by_product() function is not available.
Since this function is not available, which function can we use to access the Vendor ID by product?
-
May 19, 2023 at 1:36 PM #192269Sangita Support SquadKeymaster
Hi @design Kindly replace $vendor_id = wcmp_get_vendor_id_by_product($product_id); with $vendor_id = get_mvx_product_vendors( $product_id )->id; and check .
-
May 19, 2023 at 5:52 PM #192279AnonymousInactive
Thank you, that solved the error, but still does not fetch the results.
I managed to put some new code together which comes close to giving me a proper result:
add_action(‘woocommerce_before_checkout_form’, ‘display_vendor_store_descriptions_on_checkout’);
function display_vendor_store_descriptions_on_checkout() {
// Get the current cart instance
$cart = WC()->cart;// Array to store the vendor IDs
$vendor_ids = array();// Loop through each cart item
foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
// Get the product ID
$product_id = $cart_item[‘product_id’];// Get the vendor ID for the product
$vendor_id = get_mvx_product_vendors($product_id)->id;// Add the vendor ID to the array if it doesn’t already exist
if (!in_array($vendor_id, $vendor_ids)) {
$vendor_ids[] = $vendor_id;
}
}// Loop through the vendor IDs and display the store descriptions
if (!empty($vendor_ids)) {
echo ‘<h2>Notices:</h2>’;
foreach ($vendor_ids as $vendor_id) {
$store_description = get_vendor_store_description_for_id($vendor_id);
if (!empty($store_description)) {
echo ‘<div class=”description_data”>’ . $store_description . ‘</div>’;
}
}
}
}function get_vendor_store_description_for_id($vendor_id) {
// Implement your logic to retrieve the store description for a given vendor ID
// Replace this example implementation with your actual code// Assuming you have a way to fetch vendor data based on the vendor ID
// Modify this line to access the correct vendor data source (e.g., database, API)
$vendor_data = array(
7 => array(‘store_description’ => ”),
6 => array(‘store_description’ => ”)
);if (isset($vendor_data[$vendor_id]) && isset($vendor_data[$vendor_id][‘store_description’])) {
return $vendor_data[$vendor_id][‘store_description’];
}
return ”;
}Unfortunately I need to find the specific method or location where the store descriptions are stored in MultivendorX to be able to make it work…
-
May 22, 2023 at 6:25 PM #192348promitaKeymaster
Kindly add the below code in the functions.php file of your active theme –
add_action('woocommerce_before_checkout_form', 'display_vendor_store_descriptions_on_checkout'); function display_vendor_store_descriptions_on_checkout() { // Get the current cart instance $cart = WC()->cart; // Array to store the vendor IDs $vendor_ids = array(); // Loop through each cart item foreach ($cart->get_cart() as $cart_item_key => $cart_item) { // Get the product ID $product_id = $cart_item['product_id']; // Get the vendor ID for the product $vendor_id = get_mvx_product_vendors($product_id)->id; // Add the vendor ID to the array if it doesn't already exist if (!in_array($vendor_id, $vendor_ids)) { $vendor_ids[] = $vendor_id; } } // Loop through the vendor IDs and display the store descriptions if (!empty($vendor_ids)) { echo "Notices:"; foreach ($vendor_ids as $vendor_id) { $store_description = get_user_meta( $vendor_id, '_vendor_description', true ); if (!empty($store_description)) { echo $store_description; } } } }
Copy -
May 23, 2023 at 1:23 PM #192366AnonymousInactive
Thank you so much that works perfectly.
I have one final question.
I need to try and display possible shipping zones on the product pages and MVX seems to handle those differently. I put together this code to create a shortcode:
// Register the shortcode
add_shortcode(‘multivendor_shipping_zones’, ‘display_multivendor_shipping_zones’);// Shortcode callback function
function display_multivendor_shipping_zones() {
// Get the current product ID
$product_id = get_the_ID();// Get the vendor ID for the product
$vendor_id = get_mvx_product_vendors($product_id)->id;// Get the shipping zones for the vendor
$shipping_zones = get_vendor_shipping_zones($vendor_id);// Display the shipping zones
if (!empty($shipping_zones)) {
$output = ‘<h3>Available Shipping Zones:</h3>’;
foreach ($shipping_zones as $zone) {
$output .= ‘<div class=”shipping-zone”>’;
$output .= ‘‘ . $zone[‘zone_name’] . ‘<br>’;
$output .= ‘Shipping Methods: ‘ . implode(‘, ‘, $zone[‘shipping_methods’]) . ‘<br>’;
$output .= ‘</div>’;
}
return $output;
}return ”; // Return empty string if no shipping zones found
}This gives me a fatal error though, it seems I need to set up an appropriate function that retrieves the vendor ID for the MultivendorX plugin. Could you assist?
-
May 24, 2023 at 10:51 AM #192392Sangita Support SquadKeymaster
Kindly replace this $shipping_zones = get_vendor_shipping_zones($vendor_id); with $shipping_zones = mvx_get_shipping_zone(”, $vendor_id); and check .
-
May 24, 2023 at 12:01 PM #192393AnonymousInactive
Thanks for that. Seems we are one step closer.
I can now display all shipping zones using this code, but I’m having trouble only showing the ones available to a product when the shortcode is placed on it’s page. Here’s my code:
// Register the shortcode
add_shortcode(‘multivendor_shipping_zones’, ‘display_multivendor_shipping_zones’);// Shortcode callback function
function display_multivendor_shipping_zones() {
// Get the current product ID
$product_id = get_the_ID();// Get the vendor ID for the product
$vendor_id = get_mvx_product_vendors($product_id)->id;// Get the shipping zones for the vendor
$shipping_zones = mvx_get_shipping_zone(”, $vendor_id);// Display the shipping zones
if (!empty($shipping_zones)) {
$output = ‘<h3>Available Shipping Zones:</h3>’;
foreach ($shipping_zones as $zone) {
$output .= ‘<div class=”shipping-zone”>’;
$output .= ‘‘ . $zone[‘zone_name’] . ‘<br>’;
$output .= ‘Shipping Methods: ‘ . implode(‘, ‘, $zone[‘shipping_methods’]) . ‘<br>’;
$output .= ‘</div>’;
}
return $output;
}return ”; // Return empty string if no shipping zones found
} -
May 24, 2023 at 5:28 PM #192422NerdySupportExpert MoumitaKeymaster
@design, can you please explain what exact flow are you looking for so we can assist you with the coding flow you need to follow?
-
May 24, 2023 at 6:27 PM #192426AnonymousInactive
Hi, I need to achieve 2 things.
1. I need to create a shortcode, that when placed on a product page, will display available shipping zones for that product’s vendor.
2. I need to create another shortcode, this time one that displays all products available in a specific shipping zone, for instance “Gauteng, South Africa”
-
May 25, 2023 at 8:51 PM #192453NerdySupportExpert MoumitaKeymaster
Hi, our replies are inline :
1. I need to create a shortcode, that when placed on a product page, will display available shipping zones for that product’s vendor.
>> In order to make this shortcode you need to fetch the data using these functions and build your code:
$vendor_id = get_mvx_product_vendors($product_id)->id; $shipping_zones = mvx_get_shipping_zone('', $vendor_id);
Copy2. I need to create another shortcode, this time one that displays all products available in a specific shipping zone, for instance “Gauteng, South Africa”
>> WooCommerce doesn’t have shipping data per product by default. Do you have any woocommerce shortcode that does give you this data?
-
May 26, 2023 at 12:01 PM #192472AnonymousInactive
Thanks for that.
I used the following code to try and create the shortcode:
function display_shipping_zones_shortcode() {
global $product;// Check if the product exists
if (!$product) {
return ‘Product not found.’;
}// Get the product vendor ID
$vendor_id = get_mvx_product_vendors($product->get_id())->id;// Get the shipping zones for the vendor
$shipping_zones = mvx_get_shipping_zone(”, $vendor_id);// Prepare the HTML output
$output = ‘- ‘;
- ‘ . $shipping_zone[‘zone_name’] . ‘
foreach ($shipping_zones as $shipping_zone) {
$output .= ‘‘;
}$output .= ‘
‘;
return $output;
}
add_shortcode(‘shipping_zones’, ‘display_shipping_zones_shortcode’);Sadly it does not seem to work.
-
May 27, 2023 at 2:26 PM #192507NerdySupportExpert MoumitaKeymaster
That is probably woocommerce doesn’t save shipping data per product.
In that case, you need plugin like WooCommerce Per Product shipping, they might save shipping data per products. -
July 29, 2023 at 12:08 PM #194764Sangita Support SquadKeymaster
Its been a while and we have not heard back from you. We presume your issue is solved now. We are closing this thread as of now. If you need help or face issue in future please open a new thread.
-
-
AuthorPosts
The topic ‘Display Store Descriptions for products in the cart on Cart & Checkout pages’ is closed to new replies.