WooCommerce Plugin Not Showing - woocommerce

I've bought a plugin which has a product table for the product page, however it doesn't show on the product page. I put the website into debug mode and this came up.
Notice: Undefined index: price_table_on in /www/eroofingcouk_311/public/wp-content/plugins/elex-woocommerce-dynamic-pricing-and-discounts-premium/public/elex-dynamic-pricing-plugin-public.php on line 183
function elex_dp_show_pricing_table() {
$selected_role=get_option('elex_dp_allowed_roles_to_show_pricing_table');
if(!empty($selected_role) ) {
$user = wp_get_current_user();
if(!count(array_intersect($user->roles, $selected_role)) > 0) {
return;
}
}
$path= dirname(__FILE__) ."/elex-single-product-pricing-table.php";
if ($GLOBALS['settings']['price_table_on_off'] == 'enable' && file_exists($path) == true ) {
include "elex-single-product-pricing-table.php";
}
Line 183 is if ($GLOBALS['settings']['price_table_on_off'] == 'enable' && file_exists($path) == true ) {
I was wondering if anyone had any idea what the issue is with it and how to fix it?

Related

How do we get admin current screen by post id instead of screen id?

I need to add css on one single admin page which has post=183 .. Here id is 183.. The below code will work for all the pages but in my case I just want this to have effect in single page. So the best thing will have to be through page/post_id.
function this_screen() {
$current_screen = get_current_screen();
if(( $current_screen ->id === "page") ) {
wp_enqueue_style(
'gp_fp',
get_template_directory_uri() . '/admin/css/block.css');
}
}
Appreciate help.
I would check that:
Current page is admin (so it won't affect the front-end)
Current page is post ID = 183
$post_id = 183;
if (is_admin() && get_post_status($post_id) === false) {
// do something
}
Reference: https://tommcfarlin.com/wordpress-post-exists-by-id/

Wordpress. How to use shortcode with if else statement?

I have following code but it's displaying shortcode in text rather than showing results of shortcode.
$curr_user_id = get_current_user_id();
// the value is 0 if the user isn't logged-in
if ( $curr_user_id != 0 ) {
// we know now the user is logged-in, so we can use his/her ID to get the user meta
$um_value = get_user_meta( $curr_user_id, 'user_phone', true );
// now we check if the value is correct
if ( ! empty( $um_value ) && $um_value == 'French' ) {
// if so we can output something
echo '[ld_course_list course_category_name="french" col=4 progress_bar=true]';
} else {
// else the code, eg.
echo '[ld_course_list course_category_name="english" col=4 progress_bar=true]';
}
}
Above code will result in text below rather than showing results of the shortcode
[ld_course_list course_category_name="english" col=4
progress_bar=true]
How do I change my code so it actually runs shortcode?
Thank you.
Following code worked. Only problem is do_shortcode is breaking stylesheet. Anyone know why or how to fix it?
<?
$curr_user_id = get_current_user_id();
// the value is 0 if the user isn't logged-in
if ( $curr_user_id != 0 ) {
// we know now the user is logged-in, so we can use his/her ID to get the user meta
$um_value = get_user_meta( $curr_user_id, 'user_phone', true );
// now we check if the value is correct
if ( ! empty( $um_value ) && $um_value == 'French' ) {
// if so we can output something
echo do_shortcode('[ld_course_list course_category_name="french" col=4 progress_bar=true]');
} else {
// else the code, eg.
echo do_shortcode('[ld_course_list course_category_name="english" col="4" progress_bar="true"]');
}
}
?>
You are using it in wrong way, the method you are trying is used inside wordpress pages, posts etc.
To use inside plugin, theme or any other .php file, use WordPress function called do_shortcode() that lets you add shortcodes directly in your themes and plugins.
Add it like this:
echo do_shortcode("[ld_course_list course_category_name="english" col=4 progress_bar=true]");

How to sort listings in search page in wpgeodirectory?

The sort by option dissapears in search page whereas it appears in show all listings.
How to show also the sort by in "search page" ?
Go to
plugins\geodirectory\geodirectory-functions\custom_functions.php
line 622
if ( is_search() ) {
return;
}
and comment return
if ( is_search() ) {
// return;
}

Based on category ids I want to include different headers

Based on category ids I want to include different headers.
Eg:
If array of category id - 1,2,3 include header1.php
elseif array of category id - 4,5,6 include header2.php
I just wrote the basic flow on how I want it.
What should be the actual code go and where should I put it.
The code which I've used is
<?php
// Get the current user level from WP
$user = wp_get_current_user();
// Get user levels from WishlistMembers
$levels = WLMAPI::GetUserLevels($user->ID);
// Then run the check for the level you want like this:
if(in_array('Free', $levels) && in_array('Print', $levels) && in_array('Web', $levels) && (is_category(array(78, 'artilces-web', 'Articles')) || is_category(array(82, 'book-review-web', 'Book Review')) || is_category(array(87, 'books-at-glance-web', 'Books at Glance')) )){
// Display web subscriber header
include("header3.php");
}
elseif(in_array('Free', $levels) && in_array('Print', $levels)){
// Display print subscriber header
include("header2.php");
}
elseif (in_array('Free', $levels) && in_array('Web', $levels) && (is_category(array(78, 'artilces-web', 'Articles')) || is_category(array(82, 'book-review-web', 'Book Review')) || is_category(array(87, 'books-at-glance-web', 'Books at Glance')) )){
// Display web subscriber header
include("header3.php");
}
elseif (in_array('Print', $levels) && in_array('Web', $levels) && (is_category(array(78, 'artilces-web', 'Articles')) || is_category(array(82, 'book-review-web', 'Book Review')) || is_category(array(87, 'books-at-glance-web', 'Books at Glance')) )){
// Display web subscriber header
include("header3.php");
}
elseif(in_array('Free', $levels)){
// Display free subscriber header
include("header1.php");
}
elseif (in_array('Print', $levels)){
// Display print subscriber header
include("header2.php");
}
elseif (in_array('Web', $levels) && (is_category(array(78, 'artilces-web', 'Articles')) || is_category(array(82, 'book-review-web', 'Book Review')) || is_category(array(87, 'books-at-glance-web', 'Books at Glance')) )){
// Display web subscriber header
include("header3.php");
}
else {
include("header.php");
}
?>
You should try this:-
if( in_category( array(1,2,3) ) )
{
//Call Here header1.php
get_template_part( 'header1');
}
elseif( in_category( array(4,5,6) ) )
{
//Call Here header2.php
get_template_part( 'header2');
} else {
get_header();
}
Hope this will help you..

add custom class to wordpress nav menu item based on specific condition

I want to add current-menu-item class to the li if it is a single page.
I am trying to do this by using wp_nav_menu_objects hook with a custom function but don't know how to get the particular menu item and set a condition to assign the class to it.
Here is the code.
add_filter('wp_nav_menu_objects' , 'my_menu_class');
function my_menu_class($menu) {
//if it is a single post page of a particular post type (in this case 'property')
if( is_single() && is_post_type_archive( 'property' ) ) {
//get all the menu items
foreach($menu as $key => $item) {
// check if the menu item is "Commercial Property"
if($item == "Commercial Property") {
//assign the class to that menu item
$menu[$key]->classes[] = 'current-menu-item';
}
}
}
return $menu;
}
This code is just to represent the logic. Please suggest if what I need can be achieved with this method or there is a better approach to it.
Thanks.
In my WP theme, I wanted to remove all wordpess menu classes, add my own and on specific condition ( for example if the menu has an active class ) to add another class. Here s my code
function add_custom_classes($classes){
$newClasses[] = "navigation__item";
if( in_array('current_page_item', $classes) ){
array_push($newClasses, "navigation__item-active");
}
return $newClasses;
}
add_filter('nav_menu_css_class', 'add_custom_classes', 100, 1);
add_filter('nav_menu_item_id', 'add_custom_classes', 100, 1);
add_filter('page_css_class', 'add_custom_classes', 100, 1);
You can add your own conditions
is_single is actually looking for a single post. You need is_page
Wordpress already provides the class if it is a single page
current-post-ancestor
on any post detail page you can inspect the menu you will find that class so in other way you can utilize current-post-ancestor class for what you need to do
Hope it makes sense
I have solved it using the HTTP_REFERER to set conditions in the same function.
Don't feel it is the best way to achieve this but it sorts me out.
Here is the code if anyone else needs a reference.
function nav_menu_class($menu) {
//To dynamically get the directory path from the URL irrespective of the local or web server.
$ref = $_SERVER['HTTP_REFERER']; // prev page url.
$split_ref = pathinfo($ref); // splitting the url to seperate the directory (http://dev.calyxagency.com/horizoncapital/site-new/) from the file path.
$dir_path .= $split_ref[ "dirname" ]; // extracting the host + directory from the full path
$class = 'current-menu-item'; // class to be assigned.
foreach($menu as $key => $item) {
if( $menu[$key]-> ID == 101 ) { // check if the menu item matches this ID
if( $ref == $dir_path.'/properties-to-let/' || $ref == $dir_path.'/properties-for-sale/' || $ref == $dir_path.'/commercial-property/' ) {
$menu[$key]->classes[] = $class;
}
} elseif( $menu[$key]-> ID == 15 ) { // check if the menu item matches this ID
if( $ref == $dir_path.'/business-for-sale/' ) { // check if the single page has come from this page for assigning current class to only this menu item
$menu[$key]->classes[] = $class;
}
} elseif( $menu[$key]-> ID == 18 ) { // check if the menu item matches this ID
if( $ref == $dir_path.'/news/' ) { // check if the single page has come from this page for assigning current class to only this menu item
$menu[$key]->classes[] = $class;
}
}
}
return $menu;
}
add_filter('wp_nav_menu_objects' , 'nav_menu_class');

Resources