admin管理员组

文章数量:1277347

I'm trying to add css classes, so that each status (active, pending, canceled) has its own css class on the frontend. Please help.

function rcp_get_status_label( $status = '' ) {

    static $labels = null;

    // Array of status labels
    if ( null === $labels ) {
        $labels = array(

            // General
            'active'    => __( 'Active', 'rcp'),
            'inactive'  => __( 'Inactive', 'rcp' ),
            'pending'   => __( 'Pending', 'rcp' ),

            // Memberships
            'cancelled' => __( 'Cancelled',  'rcp' ),
            'expired'   => __( 'Expired',   'rcp' ),
            'free'      => __( 'Free',    'rcp' ), // deprecated

            // Payments
            'abandoned' => __( 'Abandoned', 'rcp' ),
            'complete'  => __( 'Complete', 'rcp' ),
            'failed'    => __( 'Failed', 'rcp' ),
            'refunded'  => __( 'Refunded', 'rcp' ),
            'new'       => __( 'New', 'rcp' ),
            'renewal'   => __( 'Renewal', 'rcp' ),
            'upgrade'   => __( 'Upgrade', 'rcp' ),
            'downgrade' => __( 'Downgrade', 'rcp' ),

            // Discount Codes
            'disabled'  => __( 'Disabled', 'rcp' ),
        );
    }
                <td data-th="<?php esc_attr_e( 'Status', 'rcp' ); ?>">
                    <?php rcp_print_membership_status( $membership->get_id() ); ?>
                </td>

I'm trying to add css classes, so that each status (active, pending, canceled) has its own css class on the frontend. Please help.

function rcp_get_status_label( $status = '' ) {

    static $labels = null;

    // Array of status labels
    if ( null === $labels ) {
        $labels = array(

            // General
            'active'    => __( 'Active', 'rcp'),
            'inactive'  => __( 'Inactive', 'rcp' ),
            'pending'   => __( 'Pending', 'rcp' ),

            // Memberships
            'cancelled' => __( 'Cancelled',  'rcp' ),
            'expired'   => __( 'Expired',   'rcp' ),
            'free'      => __( 'Free',    'rcp' ), // deprecated

            // Payments
            'abandoned' => __( 'Abandoned', 'rcp' ),
            'complete'  => __( 'Complete', 'rcp' ),
            'failed'    => __( 'Failed', 'rcp' ),
            'refunded'  => __( 'Refunded', 'rcp' ),
            'new'       => __( 'New', 'rcp' ),
            'renewal'   => __( 'Renewal', 'rcp' ),
            'upgrade'   => __( 'Upgrade', 'rcp' ),
            'downgrade' => __( 'Downgrade', 'rcp' ),

            // Discount Codes
            'disabled'  => __( 'Disabled', 'rcp' ),
        );
    }
                <td data-th="<?php esc_attr_e( 'Status', 'rcp' ); ?>">
                    <?php rcp_print_membership_status( $membership->get_id() ); ?>
                </td>
Share Improve this question asked Nov 11, 2021 at 13:50 Mr SilverMr Silver 1
Add a comment  | 

1 Answer 1

Reset to default 0

Unless you have a different function that we are not seeing, in the <td> of your html, you are calling the function "rcp_print_membership_status", however, your function name in the first code example is "rcp_get_status_label". Are you trying to call that first function? If so:

As reads: <?php rcp_print_membership_status( $membership->get_id() ); ?>

Should read: <?php rcp_get_status_label( $membership->get_id() ); ?>

Additionally, you are not returning anything from that function so nothing will be printed/returned. If you are receiving a "status" ID and checking to see what string you should return based on that ID, you are better off just using a switch statement and NOT an array.

Are you expecting that first function to return something that is printed within the <td>?

本文标签: phpAdd css class to string