is_marginbeacon() ) { // Woo's native "Cost" column (cogs_value) must not sit beside MarginBeacon COGS. unset( $columns['cogs_value'] ); } return $columns; } /** * Hide the inactive store's cost inputs on product / variation edit screens. * * @param string $hook Admin hook. * @return void */ public function enqueue_product_edit_styles( $hook ) { if ( ! in_array( $hook, array( 'post.php', 'post-new.php', 'edit.php' ), true ) ) { return; } if ( ! $this->is_product_admin_screen() ) { return; } $canonical = new CanonicalCostSource(); if ( $canonical->is_woocommerce() ) { // MarginBeacon fields are not rendered in PHP; belt-and-suspenders for cached markup. $css = ' #_aksmb_manual_cost_field, .form-field._aksmb_manual_cost_field, .woocommerce_variable_attributes input[name^="aksmb_manual_cost"] { display: none !important; } '; } else { // Hide WooCommerce native Cost inputs while MarginBeacon is canonical. $css = ' #_cogs_value_field, #_cogs_total_value_field, .form-field._cogs_value_field, .form-field._cogs_total_value_field, .woocommerce_options_panel .cogs_field, .woocommerce_variable_attributes .cogs_field, .woocommerce_variable_attributes input[name^="variable_cogs_value"], .woocommerce_variable_attributes input[id^="variable_cogs_value"], .inline-edit-row label.cogs_value, .inline-edit-group.cogs_value, .bulk-edit-product label.cogs_value { display: none !important; } '; } wp_register_style( 'aksmb-cost-source-ui', false, array(), AKSMB_VERSION ); wp_enqueue_style( 'aksmb-cost-source-ui' ); wp_add_inline_style( 'aksmb-cost-source-ui', preg_replace( '/\s+/', ' ', trim( $css ) ) ); } /** * @return bool */ private function is_product_admin_screen() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( is_object( $screen ) ) { if ( isset( $screen->post_type ) && 'product' === $screen->post_type ) { return true; } if ( isset( $screen->id ) && in_array( (string) $screen->id, array( 'product', 'edit-product' ), true ) ) { return true; } } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $post_type = isset( $_GET['post_type'] ) ? sanitize_key( wp_unslash( $_GET['post_type'] ) ) : ''; return 'product' === $post_type; } }