Get cart item name, quantity all details woocommerce

Try this : <?php global $woocommerce; $items = $woocommerce->cart->get_cart(); foreach($items as $item => $values) { $_product = wc_get_product( $values[‘data’]->get_id()); echo “<b>”.$_product->get_title().'</b> <br> Quantity: ‘.$values[‘quantity’].'<br>’; $price = get_post_meta($values[‘product_id’] , ‘_price’, true); echo ” Price: “.$price.”<br>”; } ?> To get Product Image and Regular & Sale Price: <?php global $woocommerce; $items = $woocommerce->cart->get_cart(); foreach($items as $item => … Read more

How to add Class in using wp_nav_menu() in WordPress?

No need to create custom walker. Just use additional argument and set filter for nav_menu_css_class. For example: $args = array( ‘container’ => ”, ‘theme_location’=> ‘your-theme-loc’, ‘depth’ => 1, ‘fallback_cb’ => false, ‘add_li_class’ => ‘your-class-name1 your-class-name-2′ ); wp_nav_menu($args); Notice the new ‘add_li_class’ argument. And set the filter on functions.php function add_additional_class_on_li($classes, $item, $args) { if(isset($args->add_li_class)) { … Read more

VS Code highlighted all my wordpress function name

You have to add “wordpress” to the intelephense.stubs array setting in your VS Code settings file. This array should probably also have many other stubs listed as well. For example: (“wordpress” is at the bottom) // VS Code settings.json { // … other settings here … “intelephense.files.maxSize”: 3000000, “intelephense.stubs”: [ “apache”, “bcmath”, “bz2”, “calendar”, “com_dotnet”, … Read more

wp_nav_menu change sub-menu class name?

There is no option for this, but you can extend the ‘walker’ object that WordPress uses to create the menu HTML. Only one method needs to be overridden: class My_Walker_Nav_Menu extends Walker_Nav_Menu { function start_lvl(&$output, $depth) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<ul class=\”my-sub-menu\”>\n”; } } Then you just pass an instance of your … Read more

WordPress get plugin directory

I would suggest to use a WordPress internal constant to solve this case: $my_plugin = WP_PLUGIN_DIR . ‘/my-plugin’; if ( is_dir( $my_plugin ) ) { // plugin directory found! } Alternative The other valid alternative is to compute the path from the URL which is more complex/confusing. I would not use this code: $plugins_url = … Read more

WordPress: Disable “Add New” on Custom Post Type

There is a meta capability create_posts that is documented here and is used by WordPress to check before inserting the various ‘Add New’ buttons and links. In your custom post type declaration, add capabilities (not to be confused with cap) and then set it to false as below. register_post_type( ‘custom_post_type_name’, array( ‘capability_type’ => ‘post’, ‘capabilities’ … Read more