The syntax for adding an action in WordPress WITHIN a class is somewhat different. Your code will have to look somewhat more like the following…
class MyPluginClass {
public function __construct() {
add_action( 'init', array( $this, 'sample_insert_category') );
}
public function sample_insert_category() {
if(!term_exists('sample-category')) {
wp_insert_term(
'Sample Category',
'category',
array(
'description' => 'This is an sample category.',
'slug' => 'sample-category'
)
);
}
}
}
$mypluginclass = new MyPluginClass();
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Visual composer custom element error
- How to Display Product specific to a category with WooCommerce Plugin? [closed]
- WP WC CLI – WooCommerce setup store with wp-cli [closed]
- How does WooCommerce display a custom comment_type in Comment Admin?
- Custom Shipping method not showing in checkout
- How to prevent action in ajax request, when in admin side?
- Create or Update thousands of woocommerce products via PHP
- Is it possible to set up multistore in Woocommerce? [closed]
- How to remove the woocommerce_checkout_process action hook in woocommerce if particular project in cart [closed]
- HTML in WooCommerce settings
- Getting a List of Categories for Use in a Plugin?
- Woocommerce plugin for minimum order and add-to-card-step
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- woocommerce payment gateway callback not firing [closed]
- How to modify WCMP Rest API response?
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Woocommerce dependent plugin
- How to check current user before all actions and filters?
- New databes tables with – WooCommerce – for developers [closed]
- Change commission_status paid when withdraw_status vendor is completed
- custom payment gateway in woocommerce failed to connect to remote api server
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- how to do login using woocommerce rest api From android
- Custom Pages for Woocommerce Product-Category Pages
- Woocommerce Minimum Price for a Composite Product to add in cart
- How can I insert thousands of Woocommerce products by batch with PHP? [closed]
- Best/Correct way to add an option to a category
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- Get Every Key & Value from Array then Display All in New Line
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- Add a “View all” button on WooCommerce product archives pages
- add seperate suffix for low price and high price in woocommerce
- Cross Sells are not being shown in Cart Page. Please Help!
- Error with get_price (and others) in self-written plugin to show price
- .php file for woocommerce edit category? [closed]
- Search users with custom meta data
- WordPress custom plugin that uses woocommerce enabled payment gateway for payment [closed]
- Disable variations on woo commerce if out of stock
- How can i listing current category and Featured Category post list?
- How to get Recent Post From Each Category with Thumbnail?
- WooCommerce – I want to add functionality of one plugin to another plugin — best approach?
- How to Get Category Name When Export Products
- Add a new category for posts
- wp_query ‘s’ parameter does not work with WC_AJAX
- Grouping imported products and showing variations based on selected product
- How to overwrite the category template in a plugin
- Remove Zero Money From Previews Order woocommerce
- How to display the category name in the tab and post inside the tab in WordPress?
- How would I Redirect an existing WooCommerce customer to a specific url after Checkout
- How can i solve php upgrade problem
- Make downloadable ebook read online without download option
- woocommerce: Customize email with item total count
- show wc_add notices on particular page in woo commerce custom plugin development
- Getting the same post on my related post
- How to get the checkout form data from checkout page when place-order button is clicked
- Woocommerce convert simple products to variations
- How to make WooCommerce multiple filter with custom meta fields
- How to create a plugin with automatic update?
- category page multiple products add to cart any plugin available for woocommerce
- Getting all woocommerce products from REST API call in plugin
- “Enable Media Replace” plugin does not update serialized object in WPMeta
- Change Woo Custom Endpoint Titles from a Plugin
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- Use Case: Multiple Shipping Methods per Order
- In woocommerce, is there any way to empty wordpress default mini cart when order placed?
- Get a list of Product Categories inside a loop
- wc_get_product_terms() throws “Notice: Undefined offset: 0”
- Woocommerce list variations that are added already to cart in Single Product
- Not displaying Woocommerce product page in lightbox
- Woocommerce categories displayed on every category and shopping page
- Hide ‘add to cart’ button for some products [duplicate]
- Change pricing in Woocommerce based on Category and Product [closed]
- woocommerce product search based only title
- Adding/ Removing actions for plugins
- Problem with conditional woocommerce custom checkout field
- Unable to sync woocommerce variations
- View more posts of a sub-category
- How to insert category name above post title in a featured pages plugin?
- trying to create simple plugin to filter categories from all authors
- woocommerce blank page after clicking add to cart [closed]
- Filter EVERY category link with my plugin
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- How can I add the custom taxonomy categories to the posts and pages?
- wp_insert_post_data filter to set category
- Unable to show 4 products in a row
- The plugin generated xxx characters of unexpected output during activation
- Hook for single product thumbnail
- Predefine Product Variations for specific custom product type [closed]
- Create Custom Coupon Type
- How to create a “plugin” or “block” that can manipulate WordPress DOM in frontend?
- Create WordPress category dynamically
- Template selector for woocommerce product
- Can we install 3d product configurator into wordpress
- How to use `$order->get_discount_total()`, avoiding defoult WC decimal rounding?
- A multi-section WordPress store [closed]
- merging an array to an existing array using add_filter
- Adding Font Awesome to WP Plugin
- Populate select option with JSON file