WCMp Core
-
AuthorPosts
-
-
November 28, 2021 at 9:20 AM #131171KevinParticipant
Hi WCMp
I have created a custom shortcode to show up to 6 vendors in a list.
However, I have a problem where the code from the shortcode is being injected to the top of the content of the page INSTEAD of actually being shown where I’ve placed it in the editor.I have this code in my child theme functions.php file:
add_action(‘init’, ‘add_custom_vendor_list_shortcode’);
function add_custom_vendor_list_shortcode(){
add_shortcode(‘wcmp_frontpage_vendors’, ‘wcmp_frontpage_vendors_list’);
}function wcmp_frontpage_vendors_list() {
global $WCMp;
$frontend_assets_path = $WCMp->plugin_url . ‘assets/frontend/’;
$frontend_assets_path = str_replace(array(‘http:’, ‘https:’), ”, $frontend_assets_path);
$suffix = defined(‘WCMP_SCRIPT_DEBUG’) && WCMP_SCRIPT_DEBUG ? ” : ‘.min’;
wp_register_style(‘wcmp_vendor_list’, $frontend_assets_path . ‘css/vendor-list’ . $suffix . ‘.css’, array(), $WCMp->version);
wp_style_add_data(‘wcmp_vendor_list’, ‘rtl’, ‘replace’);
wp_enqueue_style(‘wcmp_vendor_list’);
$block_vendors = wp_list_pluck(wcmp_get_all_blocked_vendors(), ‘id’);
$vendors = get_wcmp_vendors( array(‘exclude’ => $block_vendors));
$verified_vendor_list = array();
$preferred_list = array();
foreach ($vendors as $vendor) {
if ($vendor->page_title === “vendor-name-1” || $vendor->page_title === “vendor-name-2”){
$preferred_list[] = $vendor->id;
}
}
foreach ($vendors as $vendor) {
$vendor_id = $vendor->id;
if (in_array($vendor_id, $preferred_list)) continue;
$manually_verified = get_user_meta( $vendor_id, ‘_verify_vendor’, true) == “Enable”;
$verified = get_user_meta( $vendor_id, ‘_vrified_vendor’, true) == 1;
$isVerified = $manually_verified || $verified;
$profileImage = $vendor->get_image(‘image’, array(125, 125));
if($isVerified && $profileImage && strpos($profileImage, “stdavatar”) === false) {
$verified_vendor_list[] = $vendor_id;
}
}
shuffle($verified_vendor_list);
$verified_vendor_list = array_slice($verified_vendor_list, 0, 4);
$verified_vendor_list = array_merge($verified_vendor_list, $preferred_list);
shuffle($verified_vendor_list);
?>
<div id=”wcmp-store-conatiner”>
<div class=”wcmp-store-list-wrap list-3″>
<?php
if ($verified_vendor_list && is_array($verified_vendor_list)) {
foreach ($verified_vendor_list as $vendor_id) {
$vendor = get_wcmp_vendor($vendor_id);
$image = $vendor->get_image(‘image’, array(125, 125));
$banner = $vendor->get_image(‘banner’);
?><div class=”wcmp-store-list”>
<?php do_action(‘wcmp_vendor_lists_single_before_image’, $vendor->term_id, $vendor->id); ?>
<div class=”wcmp-profile-wrap”>
<div class=”wcmp-cover-picture” style=”background-image: url(‘<?php if($banner && strpos($banner, “placeholder”) === false) echo $banner; ?>’);”></div>
<!–<div class=”store-badge-wrap”>
<?php //do_action(‘wcmp_vendor_lists_vendor_store_badges’, $vendor); ?>
</div>–>
<div class=”wcmp-store-info”>
<div class=”wcmp-store-picture”>
” id=”vendor_image_display”>
</div>
</div>
</div>
<?php //do_action(‘wcmp_vendor_lists_single_after_image’, $vendor->term_id, $vendor->id); ?>
<div class=”wcmp-store-detail-wrap” style=”text-align: center”>
<?php //do_action(‘wcmp_vendor_lists_vendor_before_store_details’, $vendor); ?>
<?php $button_text = apply_filters(‘wcmp_vendor_lists_single_button_text’, $vendor->page_title); ?>
<p class=”store-name” style=”text-transform: capitalize”><?php echo esc_html($button_text); ?></p>
<div style=”margin-top: 5px”>Verificeret <?php do_action(‘after_sold_by_text_shop_page’, $vendor); ?></div>
<div class=”button” style=”margin-top: 25px” onclick=”window.location='<?php echo esc_url($vendor->get_permalink()); ?>'”>Besøg profil</div>
<?php //do_action(‘wcmp_vendor_lists_single_after_button’, $vendor->term_id, $vendor->id); ?>
<?php //do_action(‘wcmp_vendor_lists_vendor_after_title’, $vendor); ?>
<?php //do_action(‘wcmp_vendor_lists_vendor_after_store_details’, $vendor); ?>
</div>
</div>
<?php
}
} else {
_e(‘No verified vendor found!’, ‘dc-woocommerce-multi-vendor’);
}
?>
</div>
</div>
<?php
}Se my attached images that illustrates where I’ve placed the shortcode and where the code is actually shown on the frontpage!
-
November 29, 2021 at 7:13 PM #131239MVX Support NinjaKeymaster
Hi,
Kindly tell us in which page do you want to show this shortcode.So we will help you accordingly.
Regards,
-
December 2, 2021 at 3:25 AM #131449KevinParticipantThis reply has been marked as private.
-
December 2, 2021 at 7:11 PM #131472MVX Support NinjaKeymaster
Hi,
We checked your site.
seems like code issue.It will be difficult for us to detect why the shortcode is not getting placed properly, so you need to debug this.To help you further, you need to use custom CSS to place the shortcode as per your need
Or you can modify the code as per your requirement.Regards,
-
-
AuthorPosts
The topic ‘Code from custom shortcode is injected to top of page’ is closed to new replies.