Help adding custom Elementor template display conditions for product attributes in XStore theme

[ad_1]

I’m trying to add custom Elementor template display conditions for product attributes in the XStore theme. I want to extend the available filters in the Template builder to include custom attributes. I’ve attempted to use this code snippet in Fluent Snippets:

I’ve attempted to use this code snippet in Fluent Snippets:

`add_action( ‘elementor/theme/register_conditions’, ‘register_custom_product_attribute_condition’ );`

`function register_custom_product_attribute_condition( $conditions_manager ) {`
`// Ensure the ‘woocommerce’ condition is available`
`$woocommerce_condition = $conditions_manager->get_condition( ‘woocommerce’ );`

`if ( ! $woocommerce_condition ) {`
`return;`
`}`

`class Product_Attribute_Condition extends \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {`
`public function get_name() {`
`return ‘product_attribute’;`
`}`

`public function get_label() {`
`return __( ‘Product Attribute’, ‘your-text-domain’ );`
`}`

`public function register_sub_conditions() {`
`$attribute_taxonomies = wc_get_attribute_taxonomies();`

`foreach ( $attribute_taxonomies as $taxonomy ) {`
`$this->register_sub_condition( new Product_Attribute_Sub_Condition( [`
`’label’ => $taxonomy->attribute_label,`
`’name’ => $taxonomy->attribute_name,`
`] ) );`
`}`
`}`

`public function check( $args ) {`
`return is_product() && has_term( ”, ‘pa_’ . $args[‘id’] );`
`}`
`}`

`class Product_Attribute_Sub_Condition extends \ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {`
`protected $attribute_name;`

`public function __construct( array $data = [] ) {`
`parent::__construct( $data );`
`$this->attribute_name = $data[‘name’];`
`}`

`public function get_name() {`
`return $this->attribute_name;`
`}`

`public function get_label() {`
`return $this->label;`
`}`

`public function check( $args ) {`
`return is_product() && has_term( $args[‘id’], ‘pa_’ . $this->attribute_name );`
`}`
`}`

`$woocommerce_condition->register_sub_condition( new Product_Attribute_Condition() );`
`}`

However, I’m encountering issues. The custom condition doesn’t appear in Elementor’s template display conditions, and I’m not sure if it’s compatible with XStore’s product archive pages. Has anyone successfully implemented custom Elementor template display conditions for product attributes, especially with the XStore theme?

Any guidance or alternative approaches would be greatly appreciated. Thanks in advance for your help!

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer