0

<ul> <li>このコードを function.php に入力する代わりに使用したいの<select> <option>
ですが、機能しません:

function wc_dropdown_variation_attribute_options( $args = array() ) {
.
.
.
    $html  = '<div class="tt-wrapper"><div class="tt-title-options">اندازه:</div><ul id="' . esc_attr( $id ) . '" class="tt-options-swatch options-large ' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';

    if ( ! empty( $options ) ) {
        if ( $product && taxonomy_exists( $attribute ) ) {
            // Get terms if this is a taxonomy - ordered. We need the names too.
            $terms = wc_get_product_terms(
                $product->get_id(),
                $attribute,
                array(
                    'fields' => 'all',
                )
            );

            foreach ( $terms as $term ) {
                if ( in_array( $term->slug, $options, true ) ) {
                    $html .= '<li><a href="#" value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $attribute, $product ) ) . '</a></li>';
                }
            }
        } else {
            foreach ( $options as $option ) {
                // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                $selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
                $html    .= '<li><a href="#" value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option, null, $attribute, $product ) ) . '</a></li>';
            }
        }
    }

    $html .= '</ul></div></div>';

    echo apply_filters( 'woocommerce_dropdown_variation_attribute_options_html', $html, $args ); // WPCS: XSS ok.
}

woocommerce の HTML コードを独自の HTML コードに変更するにはどうすればよいですか?
これは、この質問を投稿するための詳細です

4

1 に答える 1

1

WooCommerce のデフォルトのテーマをオーバーライドするには、テーマ フォルダに「woocommerce」サブディレクトリを作成することをお勧めします。例: /wp-content/themes/mytheme/woocommerce/ ここで、変更したいテーマを正確に指定できます。詳細については、こちらをご覧ください。

また、アクションとフィルターにフックすることもできます。送信した例では、次のフィルターにフックできます: woocommerce_dropdown_variation_attribute_options_html を使用して、最終出力を変更します。詳細については、こちらこちらをご覧ください。

于 2020-01-05T04:12:43.527 に答える