Untitled
unknown
plain_text
a year ago
3.3 kB
17
Indexable
add_action('woocommerce_after_add_to_cart_button', 'add_to_my_store_button', 100);
add_action('woocommerce_single_product_summary','add_to_my_store_button_out_of_stock', 100);
function add_to_my_store_button(){
// show button
if (is_product()){
global $post;
if(intval($post->ID) === intval(get_queried_object_id())){
if (marketking()->is_vendor(get_current_user_id())){
// only show if not my product + I don't already have it added in my store
if (get_current_user_id() !== intval(marketking()->get_product_vendor($post->ID))){
if(!marketking()->vendor_has_linkedproduct(get_current_user_id(), $post->ID)){
// if has not already been shown on the page
global $marketking_add_my_store_has_shown;
if (empty($marketking_add_my_store_has_shown)){
$marketking_add_my_store_has_shown = false;
}
if ($marketking_add_my_store_has_shown === false){
ob_start();
?>
<button type="button" id="marketking_add_product_to_my_store" name="marketking_add_product_to_my_store" value="<?php echo esc_attr($post->ID);?>"><div id="marketking_add_product_to_my_store_icon"></div><span class="dashicons <?php echo esc_attr(apply_filters('marketking_add_product_to_my_store_icon','dashicons-clipboard'));?>"></span> <?php echo apply_filters('marketking_add_product_to_my_store_text',esc_html__('Add product to my store','marketking'));?></button>
<?php
$button = apply_filters('marketking_add_product_to_my_store_button', ob_get_clean(), $post->ID);
echo $button;
$marketking_add_my_store_has_shown = true;
}
}
}
}
}
}
}
function add_to_my_store_button_out_of_stock(){
// show button
if (is_product()){
global $post;
if(intval($post->ID) === intval(get_queried_object_id())){
if (marketking()->is_vendor(get_current_user_id())){
// only show if not my product + I don't already have it added in my store
if (get_current_user_id() !== intval(marketking()->get_product_vendor($post->ID))){
if(!marketking()->vendor_has_linkedproduct(get_current_user_id(), $post->ID)){
// only show if product is not purchasable
$product = wc_get_product($post->ID);
if (!$product->is_in_stock() or !$product->is_purchasable()){
global $marketking_add_my_store_has_shown;
if (empty($marketking_add_my_store_has_shown)){
$marketking_add_my_store_has_shown = false;
}
if ($marketking_add_my_store_has_shown === false){
ob_start();
?>
<button type="button" id="marketking_add_product_to_my_store" name="marketking_add_product_to_my_store" value="<?php echo esc_attr($post->ID);?>"><div id="marketking_add_product_to_my_store_icon"></div><span class="dashicons <?php echo esc_attr(apply_filters('marketking_add_product_to_my_store_icon','dashicons-clipboard'));?>"></span> <?php echo apply_filters('marketking_add_product_to_my_store_text',esc_html__('Add product to my store','marketking'));?></button>
<?php
$button = apply_filters('marketking_add_product_to_my_store_button', ob_get_clean(), $post->ID);
echo $button;
$marketking_add_my_store_has_shown = true;
}
}
}
}
}
}
}
}Editor is loading...
Leave a Comment