Untitled
unknown
plain_text
a year ago
3.0 kB
13
Indexable
add_action('wp', function(){
global $b2bking_public;
remove_action('woocommerce_after_add_to_cart_button', array($b2bking_public,'b2bking_show_custom_information_table'));
});
add_filter( 'woocommerce_product_tabs', 'product_tab_info_table' );
function product_tab_info_table( $tabs ) {
global $post;
$post_id = $post->ID;
$product = wc_get_product($post_id);
$shortcodeusage = false;
if ($product){
static $b2bking_has_run2 = false;
if ($b2bking_has_run2 === false || $shortcodeusage === true){
if ((is_object($product) && intval($post_id) === intval(get_queried_object_id())) || $shortcodeusage === true) {
if ( is_product() || $shortcodeusage === true){
// get if 1) info table is enabled and 2) there are rows set up
$is_enabled = get_post_meta($post_id, 'b2bking_show_information_table', true);
if ($is_enabled !== 'no' || apply_filters('b2bking_show_information_table_all', false)){
// get user's group
$user_id = get_current_user_id();
$user_id = b2bking()->get_top_parent_account($user_id);
$currentusergroupidnr = b2bking()->get_user_group($user_id);
$customrows = get_post_meta($post_id, 'b2bking_product_customrows_group_'.$currentusergroupidnr, true);
// if didn't find anything as a price tier, give regular price tiers
if (empty($customrows)){
if (apply_filters('b2bking_information_table_apply_regular_all', true)){
$customrows = get_post_meta($post_id, 'b2bking_product_customrows_group_b2c', true);
}
}
// now add from dynamic rules
$rules_tiered = b2bking()->get_applicable_rules('info_table', $product->get_id());
if (isset($rules_tiered[0])){
$rules_tiered = $rules_tiered[0];
if (!empty($rules_tiered)){
if (is_array($rules_tiered)){
foreach ($rules_tiered as $index => $rule_id){
if (get_post_status($rule_id) !== 'publish'){
unset($rules_tiered[$index]);
}
}
if (!empty($rules_tiered)){
foreach ($rules_tiered as $applied_rule){
$extra_table = get_post_meta($applied_rule,'b2bking_product_customrows_group_b2c', true);
if (empty($customrows)){
$customrows = $extra_table;
} else {
$customrows .= $extra_table;
}
}
}
}
}
}
if (!empty($customrows) || apply_filters('b2bking_show_information_table_all', false)){
$b2bking_has_run2 = true;
$tabs['infotable'] = [
'title' => esc_html__( 'Information Table', 'marketking-multivendor-marketplace-for-woocommerce' ),
'priority' => 90,
'callback' => 'product_tab_info_table_content',
];
}
}
}
}
}
}
return $tabs;
}
function product_tab_info_table_content(){
do_action('b2bking_show_information_table');
}Editor is loading...
Leave a Comment