| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcodes |
| 4 |
* |
| 5 |
* @package Orderable/Classes |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
/** |
| 11 |
* Shortcodes class. |
| 12 |
*/ |
| 13 |
class Orderable_Shortcodes { |
| 14 |
|
| 15 |
/** |
| 16 |
* Init. |
| 17 |
*/ |
| 18 |
public static function run() { |
| 19 |
add_shortcode( 'orderable_add_to_cart', array( __CLASS__, 'orderable_add_to_cart' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Add to cart shortcode. |
| 24 |
* |
| 25 |
* @param array $args Shortcode arguments. |
| 26 |
* |
| 27 |
* @return stirng |
| 28 |
*/ |
| 29 |
public static function orderable_add_to_cart( $args ) { |
| 30 |
$defaults = array( |
| 31 |
'product_id' => -1, |
| 32 |
); |
| 33 |
|
| 34 |
$args = wp_parse_args( $args, $defaults ); |
| 35 |
$product = $args['product_id']; |
| 36 |
|
| 37 |
if ( $product < 0 ) { |
| 38 |
global $product; |
| 39 |
} |
| 40 |
|
| 41 |
if ( is_numeric( $product ) ) { |
| 42 |
$product = wc_get_product( $product ); |
| 43 |
} |
| 44 |
|
| 45 |
if ( empty( $product ) ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
ob_start(); |
| 50 |
?> |
| 51 |
<div class="orderable-product__actions-button"> |
| 52 |
<?php |
| 53 |
// Phpcs:ignore -- WordPress.Security.EscapeOutput.OutputNotEscaped. |
| 54 |
echo Orderable_Products::get_add_to_cart_button( $product, 'orderable-product__add-to-order' ); |
| 55 |
?> |
| 56 |
</div> |
| 57 |
<?php |
| 58 |
|
| 59 |
return ob_get_clean(); |
| 60 |
} |
| 61 |
} |
| 62 |
|