ID, 'product_cat' ); if ( ! is_wp_error( $categories ) && is_array( $categories ) && ( count( $categories ) > 0 ) ) { foreach ( $categories as $k => $v ) { $integration[] = 'in-term-' . esc_attr( $v->term_id ); } } $tags = get_the_terms( $post->ID, 'product_tag' ); if ( ! is_wp_error( $tags ) && is_array( $tags ) && ( count( $tags ) > 0 ) ) { foreach ( $tags as $k => $v ) { $integration[] = 'in-term-' . esc_attr( $v->term_id ); } } } $integration[] = $conditions[count($conditions)-1]; array_splice( $conditions, count( $conditions ), 0, $integration ); return $conditions; } // End register_conditions() /** * Register the integration's headings for the meta box. * @since 1.1.0 * @param array $headings The existing array of headings. * @return array The modified array of headings. */ public function register_conditions_headings ( $headings ) { $headings['woocommerce'] = __( 'WooCommerce', 'woosidebars' ); return $headings; } // End register_conditions_headings() /** * Register the integration's conditions reference for the meta box. * @since 1.1.0 * @param array $headings The existing array of conditions. * @return array The modified array of conditions. */ public function register_conditions_reference ( $conditions ) { $conditions['woocommerce'] = array(); $conditions['woocommerce']['wc-shop_page'] = array( 'label' => __( 'Shop Page', 'woosidebars' ), 'description' => __( 'The WooCommerce "Shop" landing page', 'woosidebars' ) ); $conditions['woocommerce']['wc-product_category'] = array( 'label' => __( 'Product Categories', 'woosidebars' ), 'description' => __( 'All product categories', 'woosidebars' ) ); $conditions['woocommerce']['wc-product_tag'] = array( 'label' => __( 'Product Tags', 'woosidebars' ), 'description' => __( 'All product tags', 'woosidebars' ) ); $conditions['woocommerce']['wc-product'] = array( 'label' => __( 'Products', 'woosidebars' ), 'description' => __( 'All products', 'woosidebars' ) ); $conditions['woocommerce']['wc-cart'] = array( 'label' => __( 'Cart Page', 'woosidebars' ), 'description' => __( 'The WooCommerce "Cart" page', 'woosidebars' ) ); $conditions['woocommerce']['wc-checkout'] = array( 'label' => __( 'Checkout Page', 'woosidebars' ), 'description' => __( 'The WooCommerce "Checkout" page', 'woosidebars' ) ); $conditions['woocommerce']['wc-account'] = array( 'label' => __( 'Account Pages', 'woosidebars' ), 'description' => __( 'The WooCommerce "Account" pages', 'woosidebars' ) ); // Setup terminologies for the "in category" and "tagged with" conditions. $terminologies = array( 'taxonomy-product_cat' => __( 'Products in the "%s" category', 'woosidebars' ), 'taxonomy-product_tag' => __( 'Products tagged "%s"', 'woosidebars' ) ); foreach ( $terminologies as $k => $v ) { if( ! isset( $conditions[$k] ) ) continue; foreach ( $conditions[$k] as $i => $j ) { $conditions[$k]['in-' . $i] = array( 'label' => sprintf( $terminologies[$k], $j['label'] ), 'description' => sprintf( $terminologies[$k], $j['label'] ) ); } } return $conditions; } // End register_conditions_reference() } // End Class // Initialise the integration. new WooSidebars_Integration_WooCommerce(); ?>