| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main ProductMeta class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Elementor\Widgets\Single; |
| 9 |
|
| 10 |
use Elementor\Controls_Manager; |
| 11 |
use RadiusTheme\SB\Helpers\Fns; |
| 12 |
use RadiusTheme\SB\Abstracts\ElementorWidgetBase; |
| 13 |
use RadiusTheme\SB\Elementor\Widgets\Controls\MetaSettings; |
| 14 |
use RadiusTheme\SB\Elementor\Widgets\Controls\ProductTaxSettings; |
| 15 |
use WC_Product; |
| 16 |
|
| 17 |
// Do not allow directly accessing this file. |
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit( 'This script cannot be accessed directly.' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Product Meta class |
| 24 |
*/ |
| 25 |
class ProductMeta extends ElementorWidgetBase { |
| 26 |
/** |
| 27 |
* Construct function |
| 28 |
* |
| 29 |
* @param array $data default array. |
| 30 |
* @param mixed $args default arg. |
| 31 |
*/ |
| 32 |
public function __construct( $data = [], $args = null ) { |
| 33 |
$this->rtsb_name = esc_html__( 'Product Meta', 'shopbuilder' ); |
| 34 |
$this->rtsb_base = 'rtsb-product-meta'; |
| 35 |
parent::__construct( $data, $args ); |
| 36 |
} |
| 37 |
/** |
| 38 |
* Widget Field |
| 39 |
* |
| 40 |
* @return array |
| 41 |
*/ |
| 42 |
public function widget_fields() { |
| 43 |
$fields = MetaSettings::widget_fields( $this ); |
| 44 |
$tax_settings = ProductTaxSettings::widget_fields( $this ); |
| 45 |
$tax_settings['meta_content']['tab'] = 'style'; |
| 46 |
$fields = $fields + $tax_settings; |
| 47 |
unset( $fields['show_label'] ); |
| 48 |
unset( $fields['meta_label_heading']['condition'] ); |
| 49 |
unset( $fields['label_typo']['condition'] ); |
| 50 |
unset( $fields['meta_label_color']['condition'] ); |
| 51 |
return $fields; |
| 52 |
} |
| 53 |
/** |
| 54 |
* Set Widget Keyword. |
| 55 |
* |
| 56 |
* @return array |
| 57 |
*/ |
| 58 |
public function get_keywords() { |
| 59 |
return [ 'SKU', 'Category', 'Tag' ] + parent::get_keywords(); |
| 60 |
} |
| 61 |
/** |
| 62 |
* Widget Field. |
| 63 |
* |
| 64 |
* @param array $controllers Control. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function apply_hooks() { |
| 69 |
add_action( 'woocommerce_product_meta_end', [ $this, 'show_brand' ], 99 ); |
| 70 |
} |
| 71 |
/** |
| 72 |
* Displays brand. |
| 73 |
*/ |
| 74 |
public function show_brand() { |
| 75 |
$product = Fns::get_product(); |
| 76 |
if ( ! $product instanceof WC_Product ) { |
| 77 |
$product = wc_get_product(); |
| 78 |
} |
| 79 |
$terms = get_the_terms( $product->get_id(), 'product_brand' ); |
| 80 |
$brand_count = is_array( $terms ) ? count( $terms ) : 0; |
| 81 |
|
| 82 |
$taxonomy = get_taxonomy( 'product_brand' ); |
| 83 |
$labels = $taxonomy->labels; |
| 84 |
|
| 85 |
/* translators: %s - Label name */ |
| 86 |
echo wc_get_brands( $product->get_id(), ', ', ' <span class="posted_in">' . sprintf( _n( '%s: ', '%s: ', $brand_count, 'shopbuilder' ), $labels->singular_name, $labels->name ), '</span>' ); // phpcs:ignore WordPress.Security.EscapeOutput |
| 87 |
} |
| 88 |
/** |
| 89 |
* Render Function |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
protected function render() { |
| 94 |
global $product; |
| 95 |
$_product = $product; |
| 96 |
$product = Fns::get_product(); |
| 97 |
$controllers = $this->get_settings_for_display(); |
| 98 |
if ( $this->is_builder_mode() ) { |
| 99 |
$this->apply_hooks(); |
| 100 |
} |
| 101 |
$this->theme_support(); |
| 102 |
// show_sku. |
| 103 |
$classes = ''; |
| 104 |
if ( ! empty( $controllers['show_sku'] ) ) { |
| 105 |
$classes .= 'rtsb-show-sku '; |
| 106 |
} |
| 107 |
if ( ! empty( $controllers['show_cat'] ) ) { |
| 108 |
$classes .= 'rtsb-show-cat '; |
| 109 |
} |
| 110 |
if ( ! empty( $controllers['show_tag'] ) ) { |
| 111 |
$classes .= 'rtsb-show-tag '; |
| 112 |
} |
| 113 |
if ( ! empty( $controllers['show_brand'] ) ) { |
| 114 |
$classes .= 'rtsb-show-brand '; |
| 115 |
} |
| 116 |
$data = [ |
| 117 |
'template' => 'elementor/single-product/meta', |
| 118 |
'controllers' => $controllers, |
| 119 |
'classes' => $classes, |
| 120 |
]; |
| 121 |
Fns::load_template( $data['template'], $data ); |
| 122 |
$this->theme_support( 'render_reset' ); |
| 123 |
$product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 124 |
} |
| 125 |
} |
| 126 |
|