AR Model Viewer for WooCommerce

Ar_Model_Viewer_For_Woocommerce_Public_Shortcode

The public-facing shortcode functionality of the plugin.

Tags
subpackage

Ar_Model_Viewer_For_Woocommerce/public

author

Table of Contents

Properties

$logger  : string
The logger of WooCommerce.
$plugin_name  : string
The ID of this plugin.
$plugin_prefix  : string
The unique prefix of this plugin.
$version  : string
The version of this plugin.

Methods

__construct()  : mixed
Initialize the class and set its properties.
ar_model_viewer_for_woocommerce_shortcode_func()  : string
Handles the [ar-model-viewer-for-woocommerce-shortcode] shortcode.
get_ar_model_viewer_settings()  : array<string|int, mixed>
Retrieves AR model viewer settings from the options page.
get_model_3d_file_or_fallback()  : string
Retrieves the 3D model file for the product or sets a fallback file from the plugin's includes directory.
get_model_alt_or_fallback()  : string
Retrieves the alt text for the 3D model or falls back to the product name or short description.
get_model_poster_or_fallback()  : string
Retrieves the 3D model poster URL or falls back to the product's main image URL.

Properties

Methods

__construct()

Initialize the class and set its properties.

public __construct(string $plugin_name, string $plugin_prefix, string $version) : mixed
Parameters
$plugin_name : string

The name of the plugin.

$plugin_prefix : string

The unique prefix of this plugin.

$version : string

The version of this plugin.

Tags
since
1.0.0

ar_model_viewer_for_woocommerce_shortcode_func()

Handles the [ar-model-viewer-for-woocommerce-shortcode] shortcode.

public ar_model_viewer_for_woocommerce_shortcode_func(array<string|int, mixed> $atts[, string|null $content = null ]) : string

Shortcode usage: [ar-model-viewer-for-woocommerce-shortcode id='123'] Enclosing content: [ar-model-viewer-for-woocommerce-shortcode id='123']custom content[/ar-model-viewer-for-woocommerce-shortcode]

Parameters
$atts : array<string|int, mixed>

Shortcode attributes.

  • 'id' (int) ID of the WooCommerce product. Default is 0.
$content : string|null = null

Shortcode enclosed content (optional).

Tags
since
1.0.0
Return values
string

HTML output of the model viewer or an error message if the product is invalid.

get_ar_model_viewer_settings()

Retrieves AR model viewer settings from the options page.

private get_ar_model_viewer_settings() : array<string|int, mixed>

This function fetches the AR model viewer settings configured in the WordPress options page using the CMB2 framework. It retrieves settings related to how the AR model is loaded, displayed, and whether AR functionality is enabled.

Tags
since
1.0.0
Return values
array<string|int, mixed>

An associative array containing AR model viewer settings such as loading behavior, reveal method, AR modes, and more.

get_model_3d_file_or_fallback()

Retrieves the 3D model file for the product or sets a fallback file from the plugin's includes directory.

private get_model_3d_file_or_fallback(WC_Product $product) : string

This function checks if the 3D model file is set for the product. If not, it will log an error and terminate the execution. The function will attempt to provide a helpful error message for the user.

Parameters
$product : WC_Product

The WooCommerce product object.

Tags
since
1.0.0
Return values
string

The URL of the 3D model file.

get_model_alt_or_fallback()

Retrieves the alt text for the 3D model or falls back to the product name or short description.

private get_model_alt_or_fallback(WC_Product $product) : string

This function checks if the 3D model alt text is set in the product metadata. If it is not set, the function will attempt to return the product name. If the product name is also not available, it will return the short description. If none of these fields are available, an error will be logged using the WooCommerce logger, and an empty string will be returned as a fallback.

Parameters
$product : WC_Product

The WooCommerce product object.

Tags
since
1.0.0
Return values
string

The alt text for the 3D model, or the product name, or the short description. If none are available, it returns an empty string.

get_model_poster_or_fallback()

Retrieves the 3D model poster URL or falls back to the product's main image URL.

private get_model_poster_or_fallback(WC_Product $product) : string

This function checks if the 3D model poster URL is set for the product. If not, it attempts to retrieve the main image URL of the product. In case the product has no main image, it logs an error and returns an empty string.

Parameters
$product : WC_Product

The WooCommerce product object.

Tags
since
1.0.0
Return values
string

The URL of the 3D model poster or the product's main image. If neither is available, an empty string is returned.


        
On this page

Search results