Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * My Setting class
- **/
- if ( ! class_exists( 'WC_my_setting' ) ) {
- class WC_my_setting {
- public function __construct() {
- add_action( 'wp_enqueue_scripts', array( $this, 'setup_styles' ) ); // Enqueue the styles
- add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'woocommerce_do_something_on_frontend' ), 30 );
- // --------------------------------------------------------------------
- // Not sure where to place this code to pull in product categories needed
- // --------------------------------------------------------------------
- $categories = $product->get_categories();
- if ( $categories ) {
- foreach ( $categories as $cat ) {
- $category_options[ $cat->slug ] = $cat->name;
- }
- }
- // --------------------------------------------------------------------
- // This is how I need the array formatted
- // --------------------------------------------------------------------
- // $category_options = array(
- // 'clothing' => __( 'Clothing', 'woocommerce' ),
- // 'hoodies' => __( 'Hoodies', 'woocommerce' ),
- // 't-shirts' => __( 'T-shirts', 'woocommerce' ),
- // 'music' => __( 'Music', 'woocommerce' ),
- // 'albums' => __( 'Albums', 'woocommerce' ),
- // 'singles' => __( 'Singles', 'woocommerce' ),
- // 'posters' => __( 'Posters', 'woocommerce' ),
- // );
- // Init settings
- $this->settings = array(
- array(
- 'name' => __( 'My Setting', 'woocommerce-my-setting' ),
- 'type' => 'title',
- 'id' => 'wc_my_setting_options'
- ),
- array(
- 'name' => __( 'Name', 'woocommerce-my-setting'' ),
- 'desc' => '',
- 'id' => 'wc_my_setting_category',
- 'type' => 'multiselect',
- 'options' => $category_options
- ),
- array( 'type' => 'sectionend', 'id' => 'woocommerce-my-setting' ),
- );
- // Default options
- add_option( 'wc_my_setting_category', '' );
- // Admin
- add_action( 'woocommerce_settings_image_options_after', array( $this, 'admin_settings' ), 20 );
- add_action( 'woocommerce_update_options_catalog', array( $this, 'save_admin_settings' ) );
- add_action( 'woocommerce_update_options_products', array( $this, 'save_admin_settings' ) );
- }
- /*-----------------------------------------------------------------------------------*/
- /* Class Functions */
- /*-----------------------------------------------------------------------------------*/
- // Load the settings
- function admin_settings() {
- woocommerce_admin_fields( $this->settings );
- }
- // Save the settings
- function save_admin_settings() {
- woocommerce_update_options( $this->settings );
- }
- // Setup styles
- function setup_styles() {
- if ( apply_filters( 'woocommerce_enqueue_styles', true ) ) {
- wp_enqueue_style( 'wc-my-setting-styles', plugins_url( '/assets/css/style.css', __FILE__ ) );
- }
- }
- }
- $WC_nb = new WC_my_setting();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement